Class: Rosemary::Changeset

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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']
  tags = attrs['tags'] || {}
  @tags               = Tags.new.merge(tags.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_atDate

Returns when the changeset was closed.

Returns:

  • (Date)

    when the changeset was closed



25
26
27
# File 'lib/rosemary/changeset.rb', line 25

def closed_at
  @closed_at
end

#created_atDate

Returns creation date of this changeset.

Returns:

  • (Date)

    creation date of this changeset



22
23
24
# File 'lib/rosemary/changeset.rb', line 22

def created_at
  @created_at
end

#idFixnum (readonly)

Unique ID

Returns:

  • (Fixnum)


7
8
9
# File 'lib/rosemary/changeset.rb', line 7

def id
  @id
end

#max_latFloat

Bounding box surrounding all changes made in this changeset

Returns:

  • (Float)


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

def max_lat
  @max_lat
end

#max_lonFloat

Bounding box surrounding all changes made in this changeset

Returns:

  • (Float)


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

def max_lon
  @max_lon
end

#min_latFloat

Bounding box surrounding all changes made in this changeset

Returns:

  • (Float)


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

def min_lat
  @min_lat
end

#min_lonFloat

Bounding box surrounding all changes made in this changeset

Returns:

  • (Float)


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

def min_lon
  @min_lon
end

#openBoolean

Returns is this changeset is still open.

Returns:

  • (Boolean)

    is this changeset is still open.



19
20
21
# File 'lib/rosemary/changeset.rb', line 19

def open
  @open
end

#tagsHash (readonly)

Tags for this object

Returns:



33
34
35
# File 'lib/rosemary/changeset.rb', line 33

def tags
  @tags
end

#uidFixnum

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

Returns:

  • (Fixnum)

    the user id of the user who last edited this object



16
17
18
# File 'lib/rosemary/changeset.rb', line 16

def uid
  @uid
end

#userRosemary::User

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

Returns:



11
12
13
# File 'lib/rosemary/changeset.rb', line 11

def user
  @user
end

Instance Method Details

#attribute_listArray

List of attributes for a Changeset

Returns:

  • (Array)


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

#attributesHash

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.

Returns:

  • (Hash)

    a hash of all non-nil attributes of this object.



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?

Returns:

  • (Boolean)


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

Returns:

  • (String)

    XML



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rosemary/changeset.rb', line 87

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