Class: Rosemary::Tags

Inherits:
Hash
  • Object
show all
Defined in:
lib/rosemary/tags.rb

Overview

A collection of OSM tags which can be attached to a Node, Way, or Relation. It is a subclass of Hash.

Instance Method Summary collapse

Instance Method Details

#[]=(key, value) ⇒ Object



22
23
24
25
26
# File 'lib/rosemary/tags.rb', line 22

def []=(key, value)
  # Ignore empty values, cause we don't want them in the OSM anyways
  return if value.blank?
  super(key, value)
end

#coderObject



7
8
9
# File 'lib/rosemary/tags.rb', line 7

def coder
  @coder ||= HTMLEntities.new
end

#to_sString

Return string with comma separated key=value pairs.

Returns:

  • (String)

    string representation



32
33
34
# File 'lib/rosemary/tags.rb', line 32

def to_s
  sort.collect{ |k, v| "#{k}=#{v}" }.join(', ')
end

#to_xml(options = {}) ⇒ Object

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



13
14
15
16
17
18
19
20
# File 'lib/rosemary/tags.rb', line 13

def to_xml(options = {})
  xml = options[:builder] ||= Builder::XmlMarkup.new
  xml.instruct! unless options[:skip_instruct]
  each do |key, value|
    # Remove leading and trailing whitespace from tag values
    xml.tag(:k => key, :v => coder.decode(value.strip)) unless value.blank?
  end unless empty?
end