Class: OpenStreetMap::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/open_street_map/member.rb

Overview

A member of an OpenStreetMap Relation.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#refObject (readonly)

ID of referenced object



13
14
15
# File 'lib/open_street_map/member.rb', line 13

def ref
  @ref
end

#roleObject

Role this member has in the relationship



7
8
9
# File 'lib/open_street_map/member.rb', line 7

def role
  @role
end

#typeObject (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(options = {})
  xml = options[:builder] ||= Builder::XmlMarkup.new
  xml.instruct! unless options[:skip_instruct]
  xml.member(:type => type, :ref => ref, :role => role)
end