Class: Rosemary::Way
Overview
Instance Attribute Summary collapse
-
#nodes ⇒ Array
readonly
Array of node IDs in this way.
Attributes inherited from Element
#changeset, #id, #tags, #timestamp, #uid, #user, #version
Class Method Summary collapse
-
.from_xml(xml_string) ⇒ Rosemary::Way
Instantiate a way from an XML representation.
Instance Method Summary collapse
-
#<<(stuff) ⇒ Rosemary::Way
Add one or more tags or nodes to this way.
- #<=>(another_way) ⇒ Object
-
#attribute_list ⇒ Object
The list of attributes for this Way.
-
#initialize(attrs = {}) ⇒ Way
constructor
Create new Way object.
- #to_xml(options = {}) ⇒ Object
- #type ⇒ Object
Methods inherited from Element
#[], #[]=, #add_tags, #attributes, from_api, #get_history_from_api, #get_relations_from_api, #initialize_copy, #is_tagged?, #method_missing, #shape, #update_attributes
Constructor Details
#initialize(attrs = {}) ⇒ Way
Create new Way object.
- id
-
ID of this way. If
nil
a new unique negative ID will be allocated. - user
-
Username
- timestamp
-
Timestamp of last change
- nodes
-
Array of Node objects and/or node IDs
21 22 23 24 25 |
# File 'lib/rosemary/way.rb', line 21 def initialize(attrs = {}) attrs.stringify_keys! @nodes = [] super(attrs) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rosemary::Element
Instance Attribute Details
#nodes ⇒ Array (readonly)
Array of node IDs in this way.
13 14 15 |
# File 'lib/rosemary/way.rb', line 13 def nodes @nodes end |
Class Method Details
.from_xml(xml_string) ⇒ Rosemary::Way
Instantiate a way from an XML representation.
71 72 73 |
# File 'lib/rosemary/way.rb', line 71 def self.from_xml(xml_string) Parser.call(xml_string, :xml) end |
Instance Method Details
#<<(stuff) ⇒ Rosemary::Way
Add one or more tags or nodes to this way.
The argument can be one of the following:
-
If the argument is a Hash or an OSM::Tags object, those tags are added.
-
If the argument is an OSM::Node object, its ID is added to the list of node IDs.
-
If the argument is an Integer or String containing an Integer, this ID is added to the list of node IDs.
-
If the argument is an Array the function is called recursively, i.e. all items in the Array are added.
Returns the way to allow chaining.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rosemary/way.rb', line 44 def <<(stuff) case stuff when Array # call this method recursively stuff.each do |item| self << item end when Rosemary::Node nodes << stuff.id when String nodes << stuff.to_i when Integer nodes << stuff else .merge!(stuff) end self # return self to allow chaining end |
#<=>(another_way) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rosemary/way.rb', line 88 def <=>(another_way) parent_compare = super(another_way) # 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_way.send(:tags) nodes_compare = self.send(:nodes).sort <=> another_way.send(:nodes).sort # don't bother to compare more stuff if nodes comparison failed return nodes_compare unless nodes_compare == 0 0 end |
#attribute_list ⇒ Object
The list of attributes for this Way
64 65 66 |
# File 'lib/rosemary/way.rb', line 64 def attribute_list # :nodoc: [:id, :version, :uid, :user, :timestamp, :changeset] end |
#to_xml(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rosemary/way.rb', line 75 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.way(attributes) do nodes.each do |node_id| xml.nd(:ref => node_id) end unless nodes.empty? .to_xml(:builder => xml, :skip_instruct => true) end end end |
#type ⇒ Object
27 28 29 |
# File 'lib/rosemary/way.rb', line 27 def type 'Way' end |