Class: Rosemary::Node
Overview
OpenStreetMap Node.
To create a new Rosemary::Node object:
node = Rosemary::Node.new(:id => "123", :lat => "52.2", :lon => "13.4", :changeset => "12", :user => "fred", :uid => "123", :visible => true, :timestamp => "2005-07-30T14:27:12+01:00")
To get a node from the API:
node = Rosemary::Node.find(17)
Instance Attribute Summary collapse
-
#lat ⇒ Object
Latitude in decimal degrees.
-
#lon ⇒ Object
Longitude in decimal degrees.
Attributes inherited from Element
#changeset, #id, #tags, #timestamp, #uid, #user, #version
Instance Method Summary collapse
- #<=>(another_node) ⇒ Object
-
#attribute_list ⇒ Object
List of attributes for a Node.
-
#initialize(attrs = {}) ⇒ Node
constructor
Create new Node object.
- #to_xml(options = {}) ⇒ Object
- #type ⇒ Object
Methods inherited from Element
#[], #[]=, #add_tags, #attributes, from_api, from_xml, #get_history_from_api, #get_relations_from_api, #initialize_copy, #is_tagged?, #method_missing, #shape, #update_attributes
Constructor Details
#initialize(attrs = {}) ⇒ Node
Create new Node object.
If id
is nil
a new unique negative ID will be allocated.
24 25 26 27 28 29 |
# File 'lib/rosemary/node.rb', line 24 def initialize(attrs = {}) attrs = attrs.dup.stringify_keys! @lon = attrs['lon'].to_f rescue nil @lat = attrs['lat'].to_f rescue nil super(attrs) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rosemary::Element
Instance Attribute Details
#lat ⇒ Object
Latitude in decimal degrees
16 17 18 |
# File 'lib/rosemary/node.rb', line 16 def lat @lat end |
#lon ⇒ Object
Longitude in decimal degrees
13 14 15 |
# File 'lib/rosemary/node.rb', line 13 def lon @lon end |
Instance Method Details
#<=>(another_node) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/rosemary/node.rb', line 51 def <=>(another_node) parent_compare = super(another_node) # don't bother to compare more stuff if parent comparison failed return parent_compare unless parent_compare == 0 return -1 if self.send(:tags) != another_node.send(:tags) 0 end |
#attribute_list ⇒ Object
List of attributes for a Node
37 38 39 |
# File 'lib/rosemary/node.rb', line 37 def attribute_list [:id, :version, :uid, :user, :timestamp, :lon, :lat, :changeset] end |
#to_xml(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/rosemary/node.rb', line 41 def to_xml( = {}) xml = [:builder] ||= Builder::XmlMarkup.new xml.instruct! unless [:skip_instruct] xml.osm(:generator => "rosemary v#{Rosemary::VERSION}", :version => Rosemary::Api::API_VERSION) do xml.node(attributes) do .to_xml(:builder => xml, :skip_instruct => true) end end end |
#type ⇒ Object
32 33 34 |
# File 'lib/rosemary/node.rb', line 32 def type 'Node' end |