Class: OpenStreetMap::Way
Overview
OpenStreetMap Way.
To create a new OpenStreetMap::Way object:
way = OpenStreetMap::Way.new()
To get a way from the API:
way = OpenStreetMap::Way.find_way(17)
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Array of node IDs in this way.
Attributes inherited from Element
#changeset, #id, #tags, #timestamp, #uid, #user, #version
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(stuff) ⇒ Object
Add one or more tags or nodes to this way.
-
#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
20 21 22 23 24 |
# File 'lib/open_street_map/way.rb', line 20 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 OpenStreetMap::Element
Instance Attribute Details
#nodes ⇒ Object (readonly)
Array of node IDs in this way.
12 13 14 |
# File 'lib/open_street_map/way.rb', line 12 def nodes @nodes end |
Class Method Details
.from_xml(xml_string) ⇒ Object
67 68 69 |
# File 'lib/open_street_map/way.rb', line 67 def self.from_xml(xml_string) Parser.call(xml_string, :xml) end |
Instance Method Details
#<<(stuff) ⇒ Object
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.
call-seq: way << something -> Way
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/open_street_map/way.rb', line 43 def <<(stuff) case stuff when Array # call this method recursively stuff.each do |item| self << item end when OpenStreetMap::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 |
#attribute_list ⇒ Object
The list of attributes for this Way
63 64 65 |
# File 'lib/open_street_map/way.rb', line 63 def attribute_list # :nodoc: [:id, :version, :uid, :user, :timestamp, :changeset] end |
#to_xml(options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/open_street_map/way.rb', line 71 def to_xml( = {}) xml = [:builder] ||= Builder::XmlMarkup.new xml.instruct! unless [:skip_instruct] xml.osm 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
26 27 28 |
# File 'lib/open_street_map/way.rb', line 26 def type 'Way' end |