Class: Rosemary::Tags
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
- #[]=(key, value) ⇒ Object
- #coder ⇒ Object
-
#to_s ⇒ String
Return string with comma separated key=value pairs.
-
#to_xml(options = {}) ⇒ Object
Return XML for these tags.
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 |
#coder ⇒ Object
7 8 9 |
# File 'lib/rosemary/tags.rb', line 7 def coder @coder ||= HTMLEntities.new end |
#to_s ⇒ String
Return string with comma separated key=value pairs.
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( = {}) xml = [:builder] ||= Builder::XmlMarkup.new xml.instruct! unless [: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 |