Recent versions of the API allow you to change a material's name in code.
If you have a tool that's using a file of data that is material-name specific then clearly you need to know which of the possible materials with similar names it is to be applied to.
There are several possibilities.
You manually add a material from a library with the name 'Stonewall', there is NO preexisting material with that name, and therefore the new material gets called 'Stonewall'.
You have a material already in the model named 'Stonewall' and you manually add a material from a library with the same name, and therefore the new material gets called 'Stonewall1'.
You have a material already in the model named 'Stonewall' and you manually add a material from a library with the same name, and therefore because there's also a material in the model named 'Stonewall1' the new material gets called 'Stonewall2' [this will go on until 'Stonewall999' and beyond!].
You have a material already in the model named 'Stonewall1' and you manually add one from a library with the name 'Stonewall', and because there's NO material in the model named exactly 'Stonewall' so the new material gets called 'Stonewall'.
So how do you decide which is the real 'Stonewall' material you want?
It's likely that the model.materials collection is in the order they are created [at least in a session].
Therefore to find the 'true' 'Stonewall' material try this:
name='Stonewall' ### or any other material name to be found... mat=Sketchup.active_model.materials.to_a.find_all{|m|m.name=~/^#{name}/}[-1]
Thus the last match in the matches list is the material last added, so logically is the one you want?
To get that material's name use mat.name...