on_the_map 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 914a50c4213246b7ccd438bb7b42fce3aa973a33
4
- data.tar.gz: a133f2e998b628a9c218dcafed4a955ab51dd9a3
3
+ metadata.gz: 811edf28a0f93de8a49c23d5392dfe0e6b7cbce5
4
+ data.tar.gz: 16977c27a4d715afde3e6d199bdadcd71eeec096
5
5
  SHA512:
6
- metadata.gz: 0a27ffe8f53ec8b1527fb7597e61e2aa892fdf242e4bcd7430a3f4766a262cbdeb38e98795f20e9ec8b252936bcdf8aa540689f5c1882e5d5d60157689edbac8
7
- data.tar.gz: 75823ab95659bdc6db3f5ff3a5d712ea054767c26dc432128fad789044d58ed6d35170db6654a7f50fd3dbf5a86c8d6d184bea3a859a77f918ce0569241ee972
6
+ metadata.gz: fd1bdb8f829cbd3a927d9b8229cdf26182616aabd1598943f3a0944d4c95acfbc29e10cdd9c621521ba92c60d6ef2f38f87c274ca9108d628844a314a66f5b2f
7
+ data.tar.gz: a63b3333a79e43bb0be5eafd122fcfa95cd56f68a7619d382eec3ad40125d175355b4703dceb689e7947a54735be142790d82e305df8297c4fd9586e1389a402
@@ -17,6 +17,15 @@ class Address
17
17
  %w{street number floor_adr} + geo_address_fields
18
18
  end
19
19
 
20
+ def self.type_of name
21
+ case name.to_sym
22
+ when :latitude, :longitude, :postal_code
23
+ :int
24
+ else
25
+ :string
26
+ end
27
+ end
28
+
20
29
  address_fields.each do |name|
21
30
  field name, type: String
22
31
  end
@@ -19,6 +19,14 @@ module OnTheMap
19
19
 
20
20
  unless value.to_s.strip.blank?
21
21
  # set address field
22
+
23
+ value = case Address.type_of(fname)
24
+ when :int
25
+ value.to_i
26
+ else
27
+ value
28
+ end
29
+
22
30
  self.address.send(meth_name, value)
23
31
 
24
32
  # update full address
@@ -56,13 +56,13 @@ module OnTheMap
56
56
 
57
57
  def latitude
58
58
  perform_geocoding unless position
59
- position[1] if position
59
+ position[1].to_i if position
60
60
  end
61
61
  alias_method :lat, :latitude
62
62
 
63
63
  def longitude
64
64
  perform_geocoding unless position
65
- position[0] if position
65
+ position[0].to_i if position
66
66
  end
67
67
  alias_method :lng, :longitude
68
68
 
@@ -1,3 +1,3 @@
1
1
  module OnTheMap
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -13,6 +13,7 @@ require 'geocoder'
13
13
 
14
14
  # Requires supporting files with custom matchers and macros, etc,
15
15
  # in ./support/ and its subdirectories.
16
+ # Dir["#{File.dirname(__FILE__)}/support/*.rb"].each {|f| require f}
16
17
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
17
18
 
18
19
  RSpec.configure do |config|
@@ -27,6 +28,9 @@ RSpec.configure do |config|
27
28
 
28
29
  config.include FactoryGirl::Syntax::Methods
29
30
 
31
+ # Stub geocoding
32
+ GeocodeStubbing.stub_geocoding!
33
+
30
34
  # == Mock Framework
31
35
  config.mock_with :rspec
32
36
 
@@ -1,86 +1,106 @@
1
- Geocoder.configure(:lookup => :test)
2
-
3
- Invalid_adr = {
4
- 'latitude' => nil,
5
- 'longitude' => nil,
6
- 'address' => nil,
7
- 'state' => nil,
8
- 'state_code' => nil,
9
- 'country' => nil,
10
- 'country_code' => nil
11
- }
12
-
13
- # Invalid
14
-
15
- Geocoder::Lookup::Test.add_stub(
16
- "blip blab", [Invalid_adr]
17
- )
18
-
19
- Geocoder::Lookup::Test.add_stub(
20
- "blip blab, blop", [Invalid_adr]
21
- )
22
-
23
- Geocoder::Lookup::Test.add_stub(
24
- "blip blab, blop, DK", [Invalid_adr]
25
- )
26
-
27
- Maglekildevej = {
28
- 'latitude' => 55.677069,
29
- 'longitude' => 12.513321,
30
- 'address' => 'Maglekildevej 18, 4th, Frederiksberg, Copenhagen, Denmark',
31
- 'state' => '',
32
- 'state_code' => '',
33
- 'country' => 'Denmark',
34
- 'country_code' => 'DK'
35
- }
36
-
37
- Gammel_kongevej = {
38
- 'latitude' => 55.67616169999999,
39
- 'longitude' => 12.5422907,
40
- 'address' => 'Gammel kongevej 123, Frederiksberg, Copenhagen, Denmark',
41
- 'state' => '',
42
- 'state_code' => '',
43
- 'country' => 'Denmark',
44
- 'country_code' => 'DK'
45
- }
46
-
47
- # Gammel kongevej
48
-
49
- Geocoder::Lookup::Test.add_stub(
50
- "Gammel kongevej 123, Frederiksberg", [Gammel_kongevej]
51
- )
52
-
53
- Geocoder::Lookup::Test.add_stub(
54
- "Gammel kongevej 123", [Gammel_kongevej]
55
- )
56
-
57
- Geocoder::Lookup::Test.add_stub(
58
- "Gammel kongevej 123, Frederiksberg, DK", [Gammel_kongevej]
59
- )
60
-
61
- Geocoder::Lookup::Test.add_stub(
62
- "Gammel kongevej 123, Frederiksberg, Denmark, DK", [Gammel_kongevej]
63
- )
64
-
65
-
66
- # Maglekildevej
67
-
68
- Geocoder::Lookup::Test.add_stub(
69
- "Maglekildevej 18, 4th, Frederiksberg", [Maglekildevej]
70
- )
71
-
72
- Geocoder::Lookup::Test.add_stub(
73
- "Maglekildevej 18, 4th", [Maglekildevej]
74
- )
75
-
76
- Geocoder::Lookup::Test.add_stub(
77
- "Maglekildevej 18, 4th, Denmark, DK", [Maglekildevej]
78
- )
79
-
80
- Geocoder::Lookup::Test.add_stub(
81
- "Maglekildevej 18, 4th, Frederiksberg, Denmark, DK", [Maglekildevej]
82
- )
83
-
84
- Geocoder::Lookup::Test.add_stub(
85
- "Maglekildevej 18, 4th, Frederiksberg, DK", [Maglekildevej]
86
- )
1
+ module GeocodeStubbing
2
+ def self.stub_geocoding!
3
+ StubGeocodeLookups.new
4
+ end
5
+ end
6
+
7
+ class StubGeocodeLookups
8
+ def initialize
9
+ Geocoder.configure(:lookup => :test)
10
+ configure
11
+ end
12
+
13
+ def configure
14
+ add_stubs :invalid_adr, :maglekildevej, :gammel_kongevej
15
+ end
16
+
17
+ protected
18
+
19
+ def add_stubs *stubs
20
+ stubs.flatten.each {|stub| add_stub stub }
21
+ end
22
+
23
+ def add_stub stub
24
+ stubber = stub_class(stub).new
25
+
26
+ stubber.places.flatten.each do |place|
27
+ Geocoder::Lookup::Test.add_stub place, [stubber.result]
28
+ end
29
+ end
30
+
31
+ def stub_class name
32
+ "StubGeocodeLookups::#{name.to_s.camelize}".constantize
33
+ end
34
+
35
+ def resolve *stubs
36
+ [stubs].flatten.map {|stub| send(stub) }
37
+ end
38
+
39
+ class Stubber
40
+ end
41
+
42
+ class InvalidAdr < Stubber
43
+ def result
44
+ {
45
+ 'latitude' => nil,
46
+ 'longitude' => nil,
47
+ 'address' => nil,
48
+ 'state' => nil,
49
+ 'state_code' => nil,
50
+ 'country' => nil,
51
+ 'country_code' => nil
52
+ }
53
+ end
54
+
55
+ def places
56
+ ["blip blab", "blip blab, blop", "blip blab, blop, DK"]
57
+ end
58
+ end
59
+
60
+ class Maglekildevej < Stubber
61
+ def result
62
+ {
63
+ 'latitude' => 55.677069,
64
+ 'longitude' => 12.513321,
65
+ 'address' => 'Maglekildevej 18, 4th, Frederiksberg, Copenhagen, Denmark',
66
+ 'state' => '',
67
+ 'state_code' => '',
68
+ 'country' => 'Denmark',
69
+ 'country_code' => 'DK'
70
+ }
71
+ end
72
+
73
+ def places
74
+ [
75
+ "Maglekildevej 18, 4th",
76
+ "Maglekildevej 18, 4th, Frederiksberg",
77
+ "Maglekildevej 18, 4th, Denmark, DK",
78
+ "Maglekildevej 18, 4th, Frederiksberg, DK",
79
+ "Maglekildevej 18, 4th, Frederiksberg, Denmark, DK"
80
+ ]
81
+ end
82
+ end
83
+
84
+ class GammelKongevej < Stubber
85
+ def result
86
+ {
87
+ 'latitude' => 55.67616169999999,
88
+ 'longitude' => 12.5422907,
89
+ 'address' => 'Gammel kongevej 123, Frederiksberg, Copenhagen, Denmark',
90
+ 'state' => '',
91
+ 'state_code' => '',
92
+ 'country' => 'Denmark',
93
+ 'country_code' => 'DK'
94
+ }
95
+ end
96
+
97
+ def places
98
+ [
99
+ "Gammel kongevej 123",
100
+ "Gammel kongevej 123, Frederiksberg",
101
+ "Gammel kongevej 123, Frederiksberg, DK",
102
+ "Gammel kongevej 123, Frederiksberg, Denmark, DK"
103
+ ]
104
+ end
105
+ end
106
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: on_the_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Mandrup