Class: OpenStreetMap::Changeset

Inherits:
Object
  • Object
show all
Defined in:
lib/open_street_map/changeset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Changeset

:nodoc:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/open_street_map/changeset.rb', line 31

def initialize(attrs = {}) #:nodoc:
  attrs.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']
  @tags       = Tags.new
  @tags[:created_by] = 'osm for ruby'
  @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_atObject

When the changeset was closed



23
24
25
# File 'lib/open_street_map/changeset.rb', line 23

def closed_at
  @closed_at
end

#created_atObject

Creation date of this changeset



20
21
22
# File 'lib/open_street_map/changeset.rb', line 20

def created_at
  @created_at
end

#idObject (readonly)

Unique ID



5
6
7
# File 'lib/open_street_map/changeset.rb', line 5

def id
  @id
end

#max_latObject

Bounding box surrounding all changes made in this changeset



26
27
28
# File 'lib/open_street_map/changeset.rb', line 26

def max_lat
  @max_lat
end

#max_lonObject

Bounding box surrounding all changes made in this changeset



26
27
28
# File 'lib/open_street_map/changeset.rb', line 26

def max_lon
  @max_lon
end

#min_latObject

Bounding box surrounding all changes made in this changeset



26
27
28
# File 'lib/open_street_map/changeset.rb', line 26

def min_lat
  @min_lat
end

#min_lonObject

Bounding box surrounding all changes made in this changeset



26
27
28
# File 'lib/open_street_map/changeset.rb', line 26

def min_lon
  @min_lon
end

#openObject

True if this changeset is still open.



17
18
19
# File 'lib/open_street_map/changeset.rb', line 17

def open
  @open
end

#tagsObject (readonly)

Tags for this object



29
30
31
# File 'lib/open_street_map/changeset.rb', line 29

def tags
  @tags
end

#uidObject

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



14
15
16
# File 'lib/open_street_map/changeset.rb', line 14

def uid
  @uid
end

#userObject

The user who last edited this object (as read from file, it is not updated by operations to this object)



9
10
11
# File 'lib/open_street_map/changeset.rb', line 9

def user
  @user
end

Instance Method Details

#attribute_listObject

List of attributes for a Changeset



59
60
61
# File 'lib/open_street_map/changeset.rb', line 59

def attribute_list
  [:id, :user, :uid, :open, :created_at, :closed_at, :min_lat, :max_lat, :min_lon, :max_lon]
end

#attributesObject

Returns 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.

call-seq: attributes -> Hash



71
72
73
74
75
76
77
78
# File 'lib/open_street_map/changeset.rb', line 71

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?

Returns:

  • (Boolean)


54
55
56
# File 'lib/open_street_map/changeset.rb', line 54

def open?
  ["yes", "1", "t", "true"].include?(open)
end

#to_xml(options = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/open_street_map/changeset.rb', line 80

def to_xml(options = {})
  xml = options[:builder] ||= Builder::XmlMarkup.new
  xml.instruct! unless options[:skip_instruct]
  xml.osm do
    xml.changeset(attributes) do
      tags.each do |k,v|
        xml.tag(:k => k, :v => v)
      end unless tags.empty?
    end
  end
end