Class: OpenStreetMap::Member
- Inherits:
-
Object
- Object
- OpenStreetMap::Member
- Defined in:
- lib/open_street_map/member.rb
Overview
A member of an OpenStreetMap Relation.
Instance Attribute Summary collapse
-
#ref ⇒ Object
readonly
ID of referenced object.
-
#role ⇒ Object
Role this member has in the relationship.
-
#type ⇒ Object
readonly
Type of referenced object (can be ‘node’, ‘way’, or ‘relation’).
Instance Method Summary collapse
-
#initialize(type, ref, role = '') ⇒ Member
constructor
Create a new Member object.
-
#to_xml(options = {}) ⇒ Object
Return XML for this way.
Constructor Details
#initialize(type, ref, role = '') ⇒ Member
Create a new Member object. Type can be one of ‘node’, ‘way’ or ‘relation’. Ref is the ID of the corresponding Node, Way, or Relation. Role is a freeform string and can be empty.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/open_street_map/member.rb', line 18 def initialize(type, ref, role='') if type !~ /^(node|way|relation)$/ raise ArgumentError.new("type must be 'node', 'way', or 'relation'") end if ref.to_s !~ /^[0-9]+$/ raise ArgumentError end @type = type @ref = ref.to_i @role = role end |
Instance Attribute Details
#ref ⇒ Object (readonly)
ID of referenced object
13 14 15 |
# File 'lib/open_street_map/member.rb', line 13 def ref @ref end |
#role ⇒ Object
Role this member has in the relationship
7 8 9 |
# File 'lib/open_street_map/member.rb', line 7 def role @role end |
#type ⇒ Object (readonly)
Type of referenced object (can be ‘node’, ‘way’, or ‘relation’)
10 11 12 |
# File 'lib/open_street_map/member.rb', line 10 def type @type end |
Instance Method Details
#to_xml(options = {}) ⇒ Object
Return XML for this way. This method uses the Builder library. The only parameter ist the builder object.
32 33 34 35 36 |
# File 'lib/open_street_map/member.rb', line 32 def to_xml( = {}) xml = [:builder] ||= Builder::XmlMarkup.new xml.instruct! unless [:skip_instruct] xml.member(:type => type, :ref => ref, :role => role) end |