Sha256: 1e760a5b9ec6a35286451dbc9c7830e2bae0cc13b947250d1b71a5fc5d153e81
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
require 'builder' module Rosemary # OpenStreetMap Node. # # To create a new Rosemary::Node object: # node = Rosemary::Node.new(:id => "123", :lat => "52.2", :lon => "13.4", :changeset => "12", :user => "fred", :uid => "123", :visible => true, :timestamp => "2005-07-30T14:27:12+01:00") # # To get a node from the API: # node = Rosemary::Node.find(17) # class Node < Element # Longitude in decimal degrees attr_accessor :lon # Latitude in decimal degrees attr_accessor :lat validates :lat, :presence => true, :numericality => {:greater_than_or_equal_to => -180, :less_than_or_equal_to => 180} validates :lon, :presence => true, :numericality => {:greater_than_or_equal_to => -90, :less_than_or_equal_to => 90} # Create new Node object. # # If +id+ is +nil+ a new unique negative ID will be allocated. def initialize(attrs = {}) attrs = attrs.dup.stringify_keys! @lon = attrs['lon'].to_f rescue nil @lat = attrs['lat'].to_f rescue nil super(attrs) end def type 'Node' end # List of attributes for a Node def attribute_list [:id, :version, :uid, :user, :timestamp, :lon, :lat, :changeset] end def to_xml(options = {}) xml = options[:builder] ||= Builder::XmlMarkup.new xml.instruct! unless options[:skip_instruct] xml.osm do xml.node(attributes) do tags.to_xml(:builder => xml, :skip_instruct => true) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rosemary-0.3.4 | lib/rosemary/node.rb |
rosemary-0.3.3 | lib/rosemary/node.rb |
rosemary-0.3.2 | lib/rosemary/node.rb |