Skip to content

Commit 8f468e0

Browse files
committed
Handle LatLng JSON.
1 parent 290cdbe commit 8f468e0

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/strava/models/lat_lng.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ def to_a
3838
@latlng
3939
end
4040

41+
alias to_h to_a
42+
alias as_json to_a
43+
44+
def to_json(*args)
45+
as_json.to_json(args)
46+
end
47+
48+
def inspect
49+
@latlng.inspect
50+
end
51+
52+
alias to_s inspect
53+
4154
def initialize(latlng = nil)
4255
@latlng = latlng
4356
end

lib/strava/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Strava
4-
VERSION = '3.0.0.pre.1'
4+
VERSION = '3.0.0.pre.2'
55
end

spec/strava/models/lat_lng_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,29 @@
102102
expect(latlng.to_a).to eq([40.7128, -74.0060])
103103
end
104104
end
105+
106+
describe '#to_h' do
107+
it 'returns the latlng array' do
108+
expect(latlng.to_h).to eq([40.7128, -74.0060])
109+
end
110+
end
111+
112+
describe '#json' do
113+
it 'returns the array JSON' do
114+
expect(latlng.as_json).to eq([40.7128, -74.0060])
115+
expect(latlng.to_json).to eq([40.7128, -74.0060].to_json)
116+
end
117+
end
118+
119+
describe '#inspect' do
120+
it 'returns the array inspect' do
121+
expect(latlng.inspect).to eq([40.7128, -74.0060].inspect)
122+
end
123+
end
124+
125+
describe 'to_s' do
126+
it 'returns the array to_s' do
127+
expect(latlng.to_s).to eq([40.7128, -74.0060].to_s)
128+
end
129+
end
105130
end

0 commit comments

Comments
 (0)