Method: OpenStreetMap::Element#method_missing
- Defined in:
- lib/open_street_map/element.rb
#method_missing(method, *args) ⇒ Object
All other methods are mapped so its easy to access tags: For instance obj.name is the same as obj.tags. This works for getting and setting tags.
node = OpenStreetMap::Node.new
node.( 'highway' => 'residential', 'name' => 'Main Street' )
node.highway #=> 'residential'
node.highway = 'unclassified' #=> 'unclassified'
node.name #=> 'Main Street'
In addition methods of the form key? are used to check boolean tags. For instance oneway can be ‘true’ or ‘yes’ or ‘1’, all meaning the same.
way.oneway?
will check this. It returns true if the value of this key is either ‘true’, ‘yes’ or ‘1’.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/open_street_map/element.rb', line 208 def method_missing(method, *args) methodname = method.to_s if methodname.slice(-1, 1) == '=' if args.size != 1 raise ArgumentError.new("wrong number of arguments (#{args.size} for 1)") end [methodname.chop] = args[0] elsif methodname.slice(-1, 1) == '?' if args.size != 0 raise ArgumentError.new("wrong number of arguments (#{args.size} for 0)") end [methodname.chop] =~ /^(true|yes|1)$/ else if args.size != 0 raise ArgumentError.new("wrong number of arguments (#{args.size} for 0)") end [methodname] end end |