Class: Rosemary::Changeset
- Inherits:
-
Object
- Object
- Rosemary::Changeset
- Defined in:
- lib/rosemary/changeset.rb
Overview
Changeset is used in OpenStreetMap to bundle several changes into a kind of “commit”
Instance Attribute Summary collapse
-
#closed_at ⇒ Date
When the changeset was closed.
-
#created_at ⇒ Date
Creation date of this changeset.
-
#id ⇒ Fixnum
readonly
Unique ID.
-
#max_lat ⇒ Float
Bounding box surrounding all changes made in this changeset.
-
#max_lon ⇒ Float
Bounding box surrounding all changes made in this changeset.
-
#min_lat ⇒ Float
Bounding box surrounding all changes made in this changeset.
-
#min_lon ⇒ Float
Bounding box surrounding all changes made in this changeset.
-
#open ⇒ Boolean
Is this changeset is still open.
-
#tags ⇒ Hash
readonly
Tags for this object.
-
#uid ⇒ Fixnum
The user id of the user who last edited this object(as read from file, it is not updated by operations to this object) API 0.6 and above only.
-
#user ⇒ Rosemary::User
The user who last edited this object (as read from file, it is not updated by operations to this object).
Instance Method Summary collapse
-
#attribute_list ⇒ Array
List of attributes for a Changeset.
-
#attributes ⇒ Hash
A hash of all non-nil attributes of this object.
-
#initialize(attrs = {}) ⇒ Changeset
constructor
:nodoc:.
-
#open? ⇒ Boolean
Is this changeset still open?.
-
#to_xml(options = {}) ⇒ String
Renders the object as an xml representation compatible to the OSM API.
Constructor Details
#initialize(attrs = {}) ⇒ Changeset
:nodoc:
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rosemary/changeset.rb', line 35 def initialize(attrs = {}) #:nodoc: attrs = attrs.dup.stringify_keys! @id = attrs['id'].to_i if attrs['id'] @uid = attrs['uid'].to_i @user = attrs['user'] @created_at = Time.parse(attrs['created_at']) rescue nil @closed_at = Time.parse(attrs['closed_at']) rescue nil @open = attrs['open'] = attrs['tags'] || {} @tags = Tags.new.merge(.dup.stringify_keys!) @tags['created_by'] = "rosemary v#{Rosemary::VERSION}" @min_lat = attrs['min_lat'].to_f @min_lon = attrs['min_lon'].to_f @max_lat = attrs['max_lat'].to_f @max_lon = attrs['max_lon'].to_f end |
Instance Attribute Details
#closed_at ⇒ Date
Returns when the changeset was closed.
25 26 27 |
# File 'lib/rosemary/changeset.rb', line 25 def closed_at @closed_at end |
#created_at ⇒ Date
Returns creation date of this changeset.
22 23 24 |
# File 'lib/rosemary/changeset.rb', line 22 def created_at @created_at end |
#id ⇒ Fixnum (readonly)
Unique ID
7 8 9 |
# File 'lib/rosemary/changeset.rb', line 7 def id @id end |
#max_lat ⇒ Float
Bounding box surrounding all changes made in this changeset
29 30 31 |
# File 'lib/rosemary/changeset.rb', line 29 def max_lat @max_lat end |
#max_lon ⇒ Float
Bounding box surrounding all changes made in this changeset
29 30 31 |
# File 'lib/rosemary/changeset.rb', line 29 def max_lon @max_lon end |
#min_lat ⇒ Float
Bounding box surrounding all changes made in this changeset
29 30 31 |
# File 'lib/rosemary/changeset.rb', line 29 def min_lat @min_lat end |
#min_lon ⇒ Float
Bounding box surrounding all changes made in this changeset
29 30 31 |
# File 'lib/rosemary/changeset.rb', line 29 def min_lon @min_lon end |
#open ⇒ Boolean
Returns is this changeset is still open.
19 20 21 |
# File 'lib/rosemary/changeset.rb', line 19 def open @open end |
#tags ⇒ Hash (readonly)
Tags for this object
33 34 35 |
# File 'lib/rosemary/changeset.rb', line 33 def @tags end |
#uid ⇒ Fixnum
The user id of the user who last edited this object(as read from file, it is not updated by operations to this object) API 0.6 and above only
16 17 18 |
# File 'lib/rosemary/changeset.rb', line 16 def uid @uid end |
#user ⇒ Rosemary::User
The user who last edited this object (as read from file, it is not updated by operations to this object)
11 12 13 |
# File 'lib/rosemary/changeset.rb', line 11 def user @user end |
Instance Method Details
#attribute_list ⇒ Array
List of attributes for a Changeset
65 66 67 |
# File 'lib/rosemary/changeset.rb', line 65 def attribute_list [:id, :user, :uid, :open, :created_at, :closed_at, :min_lat, :max_lat, :min_lon, :max_lon] end |
#attributes ⇒ Hash
A hash of all non-nil attributes of this object. Keys of this hash are :id
, :user
, and :timestamp
. For a Node also :lon
and :lat
.
76 77 78 79 80 81 82 83 |
# File 'lib/rosemary/changeset.rb', line 76 def attributes attrs = Hash.new attribute_list.each do |attribute| value = self.send(attribute) attrs[attribute] = value unless value.nil? end attrs end |
#open? ⇒ Boolean
Is this changeset still open?
59 60 61 |
# File 'lib/rosemary/changeset.rb', line 59 def open? ["yes", "1", "t", "true"].include?(open) end |
#to_xml(options = {}) ⇒ String
Renders the object as an xml representation compatible to the OSM API
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rosemary/changeset.rb', line 87 def to_xml( = {}) xml = [:builder] ||= Builder::XmlMarkup.new xml.instruct! unless [:skip_instruct] xml.osm do xml.changeset(attributes) do .each do |k,v| xml.tag(:k => k, :v => v) end unless .empty? end end end |