Class: OpenStreetMap::Relation

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

Overview

OpenStreetMap Relation.

To create a new OpenStreetMap::Relation object:

relation = OpenStreetMap::Relation.new()

To get a relation from the API:

relation = OpenStreetMap::Relation.find(17)

Instance Attribute Summary collapse

Attributes inherited from Element

#changeset, #id, #tags, #timestamp, #uid, #user, #version

Instance Method Summary collapse

Methods inherited from Element

#[], #[]=, #add_tags, #attribute_list, #attributes, from_api, #get_history_from_api, #get_relations_from_api, #initialize_copy, #is_tagged?, #method_missing, #shape, #update_attributes

Constructor Details

#initialize(attrs) ⇒ Relation

Create new Relation object.

If id is nil a new unique negative ID will be allocated.



17
18
19
20
21
# File 'lib/open_street_map/relation.rb', line 17

def initialize(attrs)
  attrs.stringify_keys!
  @members = extract_member(attrs['member'])
  super(attrs)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OpenStreetMap::Element

Instance Attribute Details

#membersObject (readonly)

Array of Member objects



12
13
14
# File 'lib/open_street_map/relation.rb', line 12

def members
  @members
end

Instance Method Details

#to_xml(option = {}) ⇒ Object

Return XML for this relation. This method uses the Builder library. The only parameter ist the builder object.



29
30
31
32
33
34
35
36
37
38
# File 'lib/open_street_map/relation.rb', line 29

def to_xml(option = {})
  xml = options[:builder] ||= Builder::XmlMarkup.new
  xml.instruct! unless options[:skip_instruct]
  xml.relation(attributes) do
    members.each do |member|
      member.to_xml(:builder => xml, :skip_instruct => true)
    end
    tags.to_xml(:builder => xml, :skip_instruct => true)
  end
end

#typeObject



23
24
25
# File 'lib/open_street_map/relation.rb', line 23

def type
  'relation'
end