opium 1.3.2 → 1.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0f70beb198984ac00eabd7d1846b019aaac4b88
4
- data.tar.gz: a3c498197bab34dfdf975896ca7433d27c9674f8
3
+ metadata.gz: 07aca24af6b9ba852256c1c3c7af22edb123b079
4
+ data.tar.gz: e74fb2a45195da1987a2a10e2d8aeb41672e027d
5
5
  SHA512:
6
- metadata.gz: e19ebe57797de055860c1e4a0007bb65857a9fa2a84e25bc0cd506859b7397c98578b98f4cdb10105cdc37156b9fed1c163992959d251e1bfaa51695d83d6c94
7
- data.tar.gz: a7426e0281a31ea40c4c24615bf9e37eba51b1409fd7025847868f2670bff81588af480b53648e3cf635102186e3c33fb3a466a324a36496adabcb530769a3bc
6
+ metadata.gz: ef07d8f75c9b1dbc346258477854c7a5c14ce63e69ec26baa05f55eba4564dbef2d5c07d42d9bc58727d116b540422414943b7264280c072c8d67d1c3f049e84
7
+ data.tar.gz: dcbea8a0e2b70fe38018fd4fb060a56ed13c4847e26f41e99cda85df4a50e6e16ff7beb3eb25f926b1db6526c00ddd16127c3f0a90f6774e828ec75f3f2e7c29
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.3.3
2
+ ### New Features
3
+ - Opium::GeoPoint now implements Comparable
4
+ - Opium::GeoPoint now has a constant, NULL_ISLAND, which has a lat/long of 0/0.
5
+
1
6
  ## 1.3.2
2
7
  ### Resolved Issues
3
8
  - #51: Queryable#translate_to_parse now attempts to ensure that constraint values
@@ -1,5 +1,7 @@
1
1
  module Opium
2
2
  class GeoPoint
3
+ include Comparable
4
+
3
5
  def initialize( value )
4
6
  self.latitude, self.longitude = *
5
7
  case value
@@ -13,29 +15,35 @@ module Opium
13
15
  raise ArgumentError.new( "invalid value for GeoPoint: \"#{ value }\"" )
14
16
  end
15
17
  end
16
-
18
+
17
19
  attr_accessor :latitude, :longitude
18
-
20
+
19
21
  def to_geo_point
20
22
  self
21
23
  end
22
-
24
+
23
25
  def to_parse
24
26
  { "__type" => "GeoPoint", "latitude" => self.latitude, "longitude" => self.longitude }
25
27
  end
26
-
28
+
27
29
  def to_s
28
30
  "#{ self.latitude },#{ self.longitude }"
29
31
  end
30
32
 
33
+ def <=>( geo_point )
34
+ [self.latitude, self.longitude] <=> [geo_point.latitude, geo_point.longitude]
35
+ end
36
+
37
+ NULL_ISLAND = new( [0, 0] ).freeze
38
+
31
39
  class << self
32
40
  def to_ruby(object)
33
41
  object.to_geo_point unless object.nil?
34
42
  end
35
-
43
+
36
44
  def to_parse(object)
37
45
  object.to_geo_point.to_parse
38
46
  end
39
47
  end
40
48
  end
41
- end
49
+ end
data/lib/opium/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opium
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
@@ -2,12 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe Opium::GeoPoint do
4
4
  subject { described_class }
5
-
5
+
6
6
  it { is_expected.to respond_to( :to_ruby, :to_parse ).with( 1 ).argument }
7
-
7
+ it { is_expected.to be <= Comparable }
8
+ it { expect( described_class.constants ).to include( :NULL_ISLAND ) }
9
+
10
+ describe Opium::GeoPoint::NULL_ISLAND do
11
+ it { is_expected.to be_frozen }
12
+ it { is_expected.to be_a Opium::GeoPoint }
13
+
14
+ it { expect( subject.latitude ).to eq 0 }
15
+ it { expect( subject.longitude ).to eq 0 }
16
+ end
17
+
8
18
  describe '.to_ruby' do
9
19
  let(:result) { subject.to_ruby( convert_from ) }
10
-
20
+
11
21
  context 'with valid object representations' do
12
22
  [ "33.33, -117.117", {latitude: 33.33, longitude: -117.117}, [33.33, -117.117], described_class.new( [33.33, -117.117] ) ].each do |value|
13
23
  let(:convert_from) { value }
@@ -17,63 +27,86 @@ describe Opium::GeoPoint do
17
27
  it( 'sets the proper longitude' ) { expect( result.longitude ).to eq -117.117 }
18
28
  end
19
29
  end
20
-
30
+
21
31
  context 'with invalid object representations' do
22
32
  [ "malformed", {latitude: 0, bad_key: :unknown}, [0], 1, 1.0, true, false ].each do |value|
23
33
  let(:convert_from) { value }
24
34
  it { expect { subject.to_ruby( value ) }.to raise_exception }
25
- end
35
+ end
26
36
  end
27
37
  end
28
-
38
+
29
39
  describe '.to_parse' do
30
40
  let(:result) { subject.to_parse( convert_from ) }
31
41
  let(:expected) { { "__type" => "GeoPoint", "latitude" => 33.33, "longitude" => -117.117 } }
32
-
42
+
33
43
  context 'with valid object representations' do
34
44
  [ "33.33, -117.117", {latitude: 33.33, longitude: -117.117}, [33.33, -117.117], described_class.new( [33.33, -117.117] ) ].each do |value|
35
45
  let(:convert_from) { value }
36
-
46
+
37
47
  it { expect { result }.to_not raise_exception }
38
48
  it { expect( result ).to eq expected }
39
- end
49
+ end
40
50
  end
41
51
  end
42
-
52
+
43
53
  describe '#initialize' do
44
54
  let(:result) { described_class.new( initialize_from ) }
45
-
55
+
46
56
  context 'with an array value' do
47
57
  let(:initialize_from) { [ 33.33, -117.117 ] }
48
-
58
+
49
59
  it { expect { result }.to_not raise_exception }
50
60
  end
51
-
61
+
52
62
  context 'with a hash value' do
53
63
  let(:initialize_from) { { latitude: 33.33, longitude: -117.117 } }
54
-
64
+
55
65
  it { expect { result }.to_not raise_exception }
56
66
  end
57
-
67
+
58
68
  context 'with a string value' do
59
69
  let(:initialize_from) { "33.33, -117.117" }
60
-
70
+
61
71
  it { expect { result }.to_not raise_exception }
62
72
  end
63
-
73
+
64
74
  context 'with anything else' do
65
75
  let(:initialize_from) { 42 }
66
-
76
+
67
77
  it { expect { result }.to raise_exception }
68
78
  end
69
79
  end
70
-
80
+
81
+ describe '#<=>' do
82
+ let(:a) { described_class.new( [0, 0] ) }
83
+ let(:result) { a <=> b }
84
+
85
+ context 'with a value less than a test value' do
86
+ let(:b) { described_class.new( [1, 1] ) }
87
+
88
+ it { expect( result ).to eq -1 }
89
+ end
90
+
91
+ context 'with a value equal to a test value' do
92
+ let(:b) { described_class.new( [0, 0] ) }
93
+
94
+ it { expect( result ).to eq 0 }
95
+ end
96
+
97
+ context 'with a value greater than a test value' do
98
+ let(:b) { described_class.new( [-1, -1] ) }
99
+
100
+ it { expect( result ).to eq 1 }
101
+ end
102
+ end
103
+
71
104
  describe "instance" do
72
105
  describe "with an array value" do
73
106
  subject { described_class.new [33.33, -117.117] }
74
107
  it { should respond_to(:latitude, :longitude, :to_geo_point, :to_parse).with(0).arguments }
75
108
  it { should respond_to(:latitude=, :longitude=).with(1).argument }
76
-
109
+
77
110
  its(:latitude) { should == 33.33 }
78
111
  its(:longitude) { should == -117.117 }
79
112
  its(:to_geo_point) { should == subject }
@@ -93,4 +126,4 @@ describe Opium::GeoPoint do
93
126
  its(:to_s) { should == "33.33,-117.117" }
94
127
  end
95
128
  end
96
- end
129
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Bowers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -372,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
372
372
  version: '0'
373
373
  requirements: []
374
374
  rubyforge_project:
375
- rubygems_version: 2.4.5.1
375
+ rubygems_version: 2.4.8
376
376
  signing_key:
377
377
  specification_version: 4
378
378
  summary: An Object Parse.com Mapping technology for defining models.