Sha256: 73c3cc9e5eb2a4e6add455e3b59be0a77efa2c363a9b15b02df759ac3805f5d5

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 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.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

9 entries across 9 versions & 1 rubygems

Version Path
rosemary-0.3.1 lib/rosemary/node.rb
rosemary-0.3.0 lib/rosemary/node.rb
rosemary-0.2.8 lib/rosemary/node.rb
rosemary-0.2.7 lib/rosemary/node.rb
rosemary-0.2.6 lib/rosemary/node.rb
rosemary-0.2.5 lib/rosemary/node.rb
rosemary-0.2.4 lib/rosemary/node.rb
rosemary-0.2.3 lib/rosemary/node.rb
rosemary-0.2.2 lib/rosemary/node.rb