nearest_time_zone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ module NearestTimeZone
2
+ class TimeZone
3
+
4
+ attr_accessor :id, :name
5
+
6
+ def initialize(id, name)
7
+ self.id, self.name = id, name
8
+ end
9
+
10
+ def id=(value)
11
+ @id = value.to_i
12
+ end
13
+
14
+ def self.all
15
+ @all ||= load_all
16
+ end
17
+
18
+ def self.find(id)
19
+ all[id.to_i]
20
+ end
21
+
22
+ private
23
+
24
+ def self.load_all
25
+ begin
26
+ Marshal.load(File.read(File.expand_path("../../../data/time_zones.dump", __FILE__)))
27
+ rescue
28
+ time_zones = CSV.open(File.expand_path("../../../data/time_zones.txt", __FILE__))
29
+ Hash[
30
+ time_zones.collect do |time_zone|
31
+ [time_zone[0].to_i, NearestTimeZone::TimeZone.new(time_zone[0].to_i, time_zone[1])]
32
+ end
33
+ ]
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module NearestTimeZone
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nearest_time_zone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nearest_time_zone"
8
+ spec.version = NearestTimeZone::VERSION
9
+ spec.authors = ["Sean Devine"]
10
+ spec.email = ["seandevine@gopartage.com"]
11
+ spec.description = %q{Quickly find the name of a time zone for a latitude and longitude without relying on a web service.}
12
+ spec.summary = %q{Quickly find the name of a time zone for a latitude and longitude without relying on a web service.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "terminal-notifier-guard"
27
+ spec.add_development_dependency "rb-fsevent", '~> 0.9.1'
28
+ spec.add_development_dependency "debugger"
29
+
30
+ spec.add_dependency "require_all"
31
+ spec.add_dependency "kdtree"
32
+ spec.add_dependency "andand"
33
+ end
data/spec/city_spec.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ module NearestTimeZone
4
+ describe City do
5
+
6
+ let(:id) { 321123 }
7
+ let(:latitude) { 12 }
8
+ let(:longitude) { 21 }
9
+ let(:time_zone_id) { 4 }
10
+ subject { City.new(id, latitude, longitude, time_zone_id) }
11
+
12
+ it "should have the right latitude" do
13
+ subject.latitude.should == latitude
14
+ end
15
+
16
+ it "should have the right longitude" do
17
+ subject.longitude.should == longitude
18
+ end
19
+
20
+ it "should have the right time zone id" do
21
+ subject.time_zone_id.should == time_zone_id
22
+ end
23
+
24
+ it "the class should have a kdtree method" do
25
+ City.kdtree.should be_a_kind_of Kdtree
26
+ end
27
+
28
+ it "should expose all the cities as a hash with the id as the key" do
29
+ City.all.first[0].should be_a_kind_of Integer
30
+ end
31
+
32
+ it "should have a nearest method that finds the right city" do
33
+ City.nearest(37.2,68.9).should == City.find(220)
34
+ end
35
+
36
+ it "should have a time zone" do
37
+ City.all.first[1].time_zone.should be_a_kind_of TimeZone
38
+ end
39
+
40
+ it "should ask for the right time zone" do
41
+ city = City.all.first[1]
42
+ TimeZone.should_receive(:find).with(city.time_zone_id)
43
+ city.time_zone
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe NearestTimeZone do
4
+
5
+ it "should have the method to" do
6
+ expect { NearestTimeZone.to(1, 3) }.to_not raise_error
7
+ end
8
+
9
+ it "should find the time zone name nearest to coordinates" do
10
+ NearestTimeZone.to(41.8500, -87.6500).should == "America/Chicago"
11
+ end
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'nearest_time_zone'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ config.order = 'random'
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module NearestTimeZone
4
+ describe TimeZone do
5
+
6
+ it "should expose all of the time zones with a hash with ids as keys" do
7
+ TimeZone.all.first[0].should be_a_kind_of Integer
8
+ end
9
+
10
+ it "should expose all of the time zones as a hash with time zone objects as values" do
11
+ TimeZone.all.first[1].should be_a_kind_of TimeZone
12
+ end
13
+
14
+ it "should have the class method find that returns the right time zone" do
15
+ id = TimeZone.all.first[0]
16
+ TimeZone.find(id).should == TimeZone.all.first[1]
17
+ end
18
+
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,222 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nearest_time_zone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Devine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: terminal-notifier-guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rb-fsevent
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: debugger
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: require_all
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: kdtree
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: andand
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Quickly find the name of a time zone for a latitude and longitude without
168
+ relying on a web service.
169
+ email:
170
+ - seandevine@gopartage.com
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - .gitignore
176
+ - .rspec
177
+ - Gemfile
178
+ - Guardfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - data/cities.txt
183
+ - data/time_zones.txt
184
+ - lib/nearest_time_zone.rb
185
+ - lib/nearest_time_zone/city.rb
186
+ - lib/nearest_time_zone/time_zone.rb
187
+ - lib/nearest_time_zone/version.rb
188
+ - nearest_time_zone.gemspec
189
+ - spec/city_spec.rb
190
+ - spec/nearest_time_zone_spec.rb
191
+ - spec/spec_helper.rb
192
+ - spec/time_zone_spec.rb
193
+ homepage: ''
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.0.0
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: Quickly find the name of a time zone for a latitude and longitude without
217
+ relying on a web service.
218
+ test_files:
219
+ - spec/city_spec.rb
220
+ - spec/nearest_time_zone_spec.rb
221
+ - spec/spec_helper.rb
222
+ - spec/time_zone_spec.rb