rosemary 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rosemary/element.rb +15 -1
- data/lib/rosemary/node.rb +13 -0
- data/lib/rosemary/relation.rb +17 -0
- data/lib/rosemary/version.rb +1 -1
- data/lib/rosemary/way.rb +16 -0
- data/rosemary.gemspec +1 -1
- data/spec/models/node_spec.rb +52 -0
- data/spec/models/relation_spec.rb +62 -0
- data/spec/models/way_spec.rb +62 -0
- metadata +3 -3
data/lib/rosemary/element.rb
CHANGED
@@ -2,6 +2,7 @@ module Rosemary
|
|
2
2
|
# This is a virtual parent class for the OSM objects Node, Way and Relation.
|
3
3
|
class Element
|
4
4
|
include ActiveModel::Validations
|
5
|
+
include Comparable
|
5
6
|
|
6
7
|
# Unique ID
|
7
8
|
# @return [Fixnum] id of this element
|
@@ -55,6 +56,19 @@ module Rosemary
|
|
55
56
|
add_tags(attrs['tag']) if attrs['tag']
|
56
57
|
end
|
57
58
|
|
59
|
+
def <=>(another_element)
|
60
|
+
attribute_list.each do |attrib|
|
61
|
+
next if self.send(attrib) == another_element.send(attrib)
|
62
|
+
|
63
|
+
if self.send(attrib) < another_element.send(attrib)
|
64
|
+
return -1
|
65
|
+
else
|
66
|
+
return 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
0
|
70
|
+
end
|
71
|
+
|
58
72
|
# Create an error when somebody tries to set the ID.
|
59
73
|
# (We need this here because otherwise method_missing will be called.)
|
60
74
|
def id=(id) # :nodoc:
|
@@ -69,7 +83,7 @@ module Rosemary
|
|
69
83
|
|
70
84
|
# The list of attributes for this object
|
71
85
|
def attribute_list # :nodoc:
|
72
|
-
[:id, :version, :uid, :user, :timestamp, :tags]
|
86
|
+
[:id, :version, :uid, :user, :timestamp, :changeset, :tags]
|
73
87
|
end
|
74
88
|
|
75
89
|
# Returns a hash of all non-nil attributes of this object.
|
data/lib/rosemary/node.rb
CHANGED
@@ -48,5 +48,18 @@ module Rosemary
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def <=>(another_node)
|
52
|
+
parent_compare = super(another_node)
|
53
|
+
# don't bother to compare more stuff if parent comparison failed
|
54
|
+
return parent_compare unless parent_compare == 0
|
55
|
+
|
56
|
+
tags_compare = self.send(:tags).sort <=> another_node.send(:tags).sort
|
57
|
+
# don't bother to compare more stuff if tags comparison failed
|
58
|
+
return tags_compare unless tags_compare == 0
|
59
|
+
|
60
|
+
0
|
61
|
+
end
|
62
|
+
|
63
|
+
|
51
64
|
end
|
52
65
|
end
|
data/lib/rosemary/relation.rb
CHANGED
@@ -39,6 +39,23 @@ module Rosemary
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
def <=>(another_relation)
|
43
|
+
parent_compare = super(another_relation)
|
44
|
+
# don't bother to compare more stuff if parent comparison failed
|
45
|
+
return parent_compare unless parent_compare == 0
|
46
|
+
|
47
|
+
members_compare = self.send(:members).sort <=> another_relation.send(:members).sort
|
48
|
+
# don't bother to compare more stuff if nodes comparison failed
|
49
|
+
return members_compare unless members_compare == 0
|
50
|
+
|
51
|
+
tags_compare = self.send(:tags).sort <=> another_relation.send(:tags).sort
|
52
|
+
# don't bother to compare more stuff if tags comparison failed
|
53
|
+
return tags_compare unless tags_compare == 0
|
54
|
+
|
55
|
+
0
|
56
|
+
end
|
57
|
+
|
58
|
+
|
42
59
|
protected
|
43
60
|
|
44
61
|
def extract_member(member_array)
|
data/lib/rosemary/version.rb
CHANGED
data/lib/rosemary/way.rb
CHANGED
@@ -84,5 +84,21 @@ module Rosemary
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
|
+
|
88
|
+
def <=>(another_way)
|
89
|
+
parent_compare = super(another_way)
|
90
|
+
# don't bother to compare more stuff if parent comparison failed
|
91
|
+
return parent_compare unless parent_compare == 0
|
92
|
+
|
93
|
+
nodes_compare = self.send(:nodes).sort <=> another_way.send(:nodes).sort
|
94
|
+
# don't bother to compare more stuff if nodes comparison failed
|
95
|
+
return nodes_compare unless nodes_compare == 0
|
96
|
+
|
97
|
+
tags_compare = self.send(:tags).sort <=> another_way.send(:tags).sort
|
98
|
+
# don't bother to compare more stuff if tags comparison failed
|
99
|
+
return tags_compare unless tags_compare == 0
|
100
|
+
|
101
|
+
0
|
102
|
+
end
|
87
103
|
end
|
88
104
|
end
|
data/rosemary.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
10
10
|
s.authors = ["Christoph Bünte, Enno Brehm"]
|
11
|
-
s.date =
|
11
|
+
s.date = Time.now
|
12
12
|
s.description = "OpenStreetMap API client for ruby"
|
13
13
|
s.email = ["info@christophbuente.de"]
|
14
14
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md"]
|
data/spec/models/node_spec.rb
CHANGED
@@ -113,4 +113,56 @@ describe Node do
|
|
113
113
|
subject.name = " Allice and Bob "
|
114
114
|
subject.to_xml.should match "\"Allice and Bob\""
|
115
115
|
end
|
116
|
+
|
117
|
+
it "should compare identity depending on tags and attributes" do
|
118
|
+
first_node = Way.new('id' => 123, 'changeset' => '123', 'version' => 1, 'user' => 'horst', 'uid' => '123', 'timestamp' => '2005-07-30T14:27:12+01:00')
|
119
|
+
first_node.tags[:name] = 'Black horse'
|
120
|
+
second_node = Way.new('id' => 123, 'changeset' => '123', 'version' => 1, 'user' => 'horst', 'uid' => '123', 'timestamp' => '2005-07-30T14:27:12+01:00')
|
121
|
+
second_node.tags[:name] = 'Black horse'
|
122
|
+
first_node.should == second_node
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not be equal when id does not match" do
|
126
|
+
first_node = Way.new('id' => 123)
|
127
|
+
second_node = Way.new('id' => 234)
|
128
|
+
first_node.should_not == second_node
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not be equal when changeset does not match" do
|
132
|
+
first_node = Way.new('changeset' => 123)
|
133
|
+
second_node = Way.new('changeset' => 234)
|
134
|
+
first_node.should_not == second_node
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not be equal when version does not match" do
|
138
|
+
first_node = Way.new('version' => 1)
|
139
|
+
second_node = Way.new('version' => 2)
|
140
|
+
first_node.should_not == second_node
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not be equal when user does not match" do
|
144
|
+
first_node = Way.new('user' => 'horst')
|
145
|
+
second_node = Way.new('user' => 'jack')
|
146
|
+
first_node.should_not == second_node
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should not be equal when uid does not match" do
|
150
|
+
first_node = Way.new('uid' => 123)
|
151
|
+
second_node = Way.new('uid' => 234)
|
152
|
+
first_node.should_not == second_node
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should not be equal when timestamp does not match" do
|
156
|
+
first_node = Way.new('timestamp' => '2005-07-30T14:27:12+01:00')
|
157
|
+
second_node = Way.new('timestamp' => '2006-07-30T14:27:12+01:00')
|
158
|
+
first_node.should_not == second_node
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should not be equal when tags do not match" do
|
162
|
+
first_node = Way.new('id' => 123)
|
163
|
+
first_node.tags[:name] = 'black horse'
|
164
|
+
second_node = Way.new('id' => 123)
|
165
|
+
second_node.tags[:name] = 'white horse'
|
166
|
+
first_node.should_not == second_node
|
167
|
+
end
|
116
168
|
end
|
@@ -23,4 +23,66 @@ describe Relation do
|
|
23
23
|
subject.members.size.should eql 2
|
24
24
|
end
|
25
25
|
|
26
|
+
it "should compare identity depending on tags and attributes" do
|
27
|
+
first_relation = Relation.new('id' => 123, 'changeset' => '123', 'version' => 1, 'user' => 'horst', 'uid' => '123', 'timestamp' => '2005-07-30T14:27:12+01:00')
|
28
|
+
first_relation.tags[:name] = 'Black horse'
|
29
|
+
second_relation = Relation.new('id' => 123, 'changeset' => '123', 'version' => 1, 'user' => 'horst', 'uid' => '123', 'timestamp' => '2005-07-30T14:27:12+01:00')
|
30
|
+
second_relation.tags[:name] = 'Black horse'
|
31
|
+
first_relation.should == second_relation
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not be equal when id does not match" do
|
35
|
+
first_relation = Relation.new('id' => 123)
|
36
|
+
second_relation = Relation.new('id' => 234)
|
37
|
+
first_relation.should_not == second_relation
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not be equal when changeset does not match" do
|
41
|
+
first_relation = Relation.new('changeset' => 123)
|
42
|
+
second_relation = Relation.new('changeset' => 234)
|
43
|
+
first_relation.should_not == second_relation
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not be equal when version does not match" do
|
47
|
+
first_relation = Relation.new('version' => 1)
|
48
|
+
second_relation = Relation.new('version' => 2)
|
49
|
+
first_relation.should_not == second_relation
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not be equal when user does not match" do
|
53
|
+
first_relation = Relation.new('user' => 'horst')
|
54
|
+
second_relation = Relation.new('user' => 'jack')
|
55
|
+
first_relation.should_not == second_relation
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not be equal when uid does not match" do
|
59
|
+
first_relation = Relation.new('uid' => 123)
|
60
|
+
second_relation = Relation.new('uid' => 234)
|
61
|
+
first_relation.should_not == second_relation
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not be equal when timestamp does not match" do
|
65
|
+
first_relation = Relation.new('timestamp' => '2005-07-30T14:27:12+01:00')
|
66
|
+
second_relation = Relation.new('timestamp' => '2006-07-30T14:27:12+01:00')
|
67
|
+
first_relation.should_not == second_relation
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not be equal when members do not match" do
|
71
|
+
first_relation = Relation.new('id' => 123)
|
72
|
+
first_relation.members << 1
|
73
|
+
first_relation.members << 2
|
74
|
+
second_relation = Relation.new('id' => 123)
|
75
|
+
second_relation.members << 1
|
76
|
+
second_relation.members << 3
|
77
|
+
first_relation.should_not == second_relation
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not be equal when tags do not match" do
|
81
|
+
first_relation = Relation.new('id' => 123)
|
82
|
+
first_relation.tags[:name] = 'black horse'
|
83
|
+
second_relation = Relation.new('id' => 123)
|
84
|
+
second_relation.tags[:name] = 'white horse'
|
85
|
+
first_relation.should_not == second_relation
|
86
|
+
end
|
87
|
+
|
26
88
|
end
|
data/spec/models/way_spec.rb
CHANGED
@@ -87,4 +87,66 @@ describe Way do
|
|
87
87
|
subject.add_tags(:wheelchair => '')
|
88
88
|
subject.to_xml.should_not match /k=\"wheelchair\"/
|
89
89
|
end
|
90
|
+
|
91
|
+
it "should compare identity depending on tags and attributes" do
|
92
|
+
first_way = Way.new('id' => 123, 'changeset' => '123', 'version' => 1, 'user' => 'horst', 'uid' => '123', 'timestamp' => '2005-07-30T14:27:12+01:00')
|
93
|
+
first_way.tags[:name] = 'Black horse'
|
94
|
+
second_way = Way.new('id' => 123, 'changeset' => '123', 'version' => 1, 'user' => 'horst', 'uid' => '123', 'timestamp' => '2005-07-30T14:27:12+01:00')
|
95
|
+
second_way.tags[:name] = 'Black horse'
|
96
|
+
first_way.should == second_way
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should not be equal when id does not match" do
|
100
|
+
first_way = Way.new('id' => 123)
|
101
|
+
second_way = Way.new('id' => 234)
|
102
|
+
first_way.should_not == second_way
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not be equal when changeset does not match" do
|
106
|
+
first_way = Way.new('changeset' => 123)
|
107
|
+
second_way = Way.new('changeset' => 234)
|
108
|
+
first_way.should_not == second_way
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should not be equal when version does not match" do
|
112
|
+
first_way = Way.new('version' => 1)
|
113
|
+
second_way = Way.new('version' => 2)
|
114
|
+
first_way.should_not == second_way
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not be equal when user does not match" do
|
118
|
+
first_way = Way.new('user' => 'horst')
|
119
|
+
second_way = Way.new('user' => 'jack')
|
120
|
+
first_way.should_not == second_way
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not be equal when uid does not match" do
|
124
|
+
first_way = Way.new('uid' => 123)
|
125
|
+
second_way = Way.new('uid' => 234)
|
126
|
+
first_way.should_not == second_way
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not be equal when timestamp does not match" do
|
130
|
+
first_way = Way.new('timestamp' => '2005-07-30T14:27:12+01:00')
|
131
|
+
second_way = Way.new('timestamp' => '2006-07-30T14:27:12+01:00')
|
132
|
+
first_way.should_not == second_way
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should not be equal when nodes do not match" do
|
136
|
+
first_way = Way.new('id' => 123)
|
137
|
+
first_way.nodes << 1
|
138
|
+
first_way.nodes << 2
|
139
|
+
second_way = Way.new('id' => 123)
|
140
|
+
second_way.nodes << 1
|
141
|
+
second_way.nodes << 3
|
142
|
+
first_way.should_not == second_way
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not be equal when tags do not match" do
|
146
|
+
first_way = Way.new('id' => 123)
|
147
|
+
first_way.tags[:name] = 'black horse'
|
148
|
+
second_way = Way.new('id' => 123)
|
149
|
+
second_way.tags[:name] = 'white horse'
|
150
|
+
first_way.should_not == second_way
|
151
|
+
end
|
90
152
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rosemary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -241,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
segments:
|
243
243
|
- 0
|
244
|
-
hash: -
|
244
|
+
hash: -3489737723584128145
|
245
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
246
|
none: false
|
247
247
|
requirements:
|