earth_tools 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/Gemfile +9 -1
- data/README.md +59 -45
- data/lib/earth_tools/result/base.rb +2 -2
- data/lib/earth_tools/result/time_zone.rb +1 -1
- data/lib/earth_tools/version.rb +1 -1
- data/test/cache_test.rb +6 -6
- data/test/configuration_test.rb +12 -25
- data/test/earth_tools_test.rb +3 -3
- data/test/fixtures/{height_(52.4822,-1.8946).xml → height/52.4822,-1.8946.xml} +0 -0
- data/test/fixtures/{sun_(40.71417,-74.00639,4,12,99,0).xml → sun/40.71417,-74.00639,4,12,99,0.xml} +0 -0
- data/test/fixtures/{timezone_(40.71417,-74.00639).xml → timezone/40.71417,-74.00639.xml} +0 -0
- data/test/fixtures/timezone/40.71655,-12.12318.xml +14 -0
- data/test/fixtures/timezone/50.21655,-54.87656.xml +14 -0
- data/test/height_test.rb +12 -16
- data/test/mock_lookup.rb +1 -1
- data/test/sunrise_sunset_test.rb +130 -51
- data/test/test_helper.rb +6 -1
- data/test/time_zone_test.rb +39 -27
- metadata +10 -8
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# earth_tools
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/earth_tools.png)](http://badge.fury.io/rb/earth_tools) [![Dependency Status](https://gemnasium.com/mckramer/earth_tools.png?travis)](https://gemnasium.com/mckramer/earth_tools) [![Code Climate](https://codeclimate.com/github/mckramer/earth_tools.png)](https://codeclimate.com/github/mckramer/earth_tools) [![Build Status](https://secure.travis-ci.org/mckramer/earth_tools.png?branch=master)](http://travis-ci.org/mckramer/earth_tools)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/earth_tools.png)](http://badge.fury.io/rb/earth_tools) [![Dependency Status](https://gemnasium.com/mckramer/earth_tools.png?travis)](https://gemnasium.com/mckramer/earth_tools) [![Code Climate](https://codeclimate.com/github/mckramer/earth_tools.png)](https://codeclimate.com/github/mckramer/earth_tools) [![Coverage Status](https://img.shields.io/coveralls/mckramer/earth_tools.svg)](https://coveralls.io/r/mckramer/earth_tools?branch=master) [![Build Status](https://secure.travis-ci.org/mckramer/earth_tools.png?branch=master)](http://travis-ci.org/mckramer/earth_tools)
|
3
3
|
|
4
4
|
`earth_tools` is a wrapper around the wonderful [earthtools.org webservices](http://www.earthtools.org/webservices.htm), which allows you to determine the sea level height, time zone, and surise/sunset times from a set of coordinates.
|
5
5
|
|
6
6
|
## Compatibility
|
7
7
|
|
8
|
-
* Supports Ruby 1.9.2 & 1.
|
8
|
+
* Supports Ruby 1.9.3, 2.0.0, & 2.1.5
|
9
9
|
|
10
10
|
Will be testing on other versions in the future.
|
11
11
|
|
@@ -13,12 +13,16 @@ Will be testing on other versions in the future.
|
|
13
13
|
|
14
14
|
Add to your Gemfile:
|
15
15
|
|
16
|
-
|
16
|
+
```ruby
|
17
|
+
gem 'earth_tools'
|
18
|
+
```
|
17
19
|
|
18
|
-
and then bundle
|
20
|
+
and then run bundle:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
$ bundle install
|
24
|
+
```
|
19
25
|
|
20
|
-
`bundle install`
|
21
|
-
|
22
26
|
and you are done!
|
23
27
|
|
24
28
|
## API
|
@@ -27,45 +31,53 @@ The run down of the 3 major functions available
|
|
27
31
|
|
28
32
|
### Time zone
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
```ruby
|
35
|
+
# API
|
36
|
+
result = EarthTools.time_zone(latitude, longitude)
|
37
|
+
# Example
|
38
|
+
result = EarthTools.time_zone(40.71417, -74.00639) # New York City
|
39
|
+
result.iso_time # => 2012-06-14 12:56:40 -0500
|
40
|
+
result.utc_offset # => -5
|
41
|
+
result.utc_time # => 2012-06-14 17:56:40 +0000
|
42
|
+
```
|
37
43
|
|
38
44
|
### Height above/below sea level
|
39
45
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
```ruby
|
47
|
+
# API
|
48
|
+
result = EarthTools.height(latitude, longitude)
|
49
|
+
# Example
|
50
|
+
result = EarthTools.height(52.4822, -1.8946) # Birmingham, AL
|
51
|
+
result.meters # => 141
|
52
|
+
result.feet # => 462.6
|
53
|
+
result.height # => 462.6 (when EarthTools::Configuration.units is set to :english units)
|
54
|
+
```
|
47
55
|
|
48
56
|
### Sunrise/sunset times
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
```ruby
|
59
|
+
# API
|
60
|
+
result = EarthTools.sunrise_sunset(latitude, longitude, month, day, timezone, dst)
|
61
|
+
# Example
|
62
|
+
result = EarthTools.sunrise_sunset(40.71417, -74.00639, 12, 4, -5, 0) # New York City, December 4th
|
63
|
+
result.sunrise # => 2012-12-04 07:05:50 -0500
|
64
|
+
result.sunset # => 2012-12-04 16:26:59 -0500
|
65
|
+
```
|
56
66
|
|
57
67
|
### Configuration
|
58
68
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
```ruby
|
70
|
+
# Configure block (set to defaults)
|
71
|
+
EarthTools.configure do |config|
|
72
|
+
config.always_raise = [] # Add any errors that you would like to be custom handled, see "Error handling" section below
|
73
|
+
config.cache = nil # Cache object (see Caching section for what methods are required)
|
74
|
+
config.cache_prefix = "earth_tools:" # Prefix to use for cache keys
|
75
|
+
config.timeout = 3 # Timeout in seconds
|
76
|
+
config.units = :english # Also, can specify :metric
|
77
|
+
end
|
78
|
+
# Static call
|
79
|
+
EarthTools::Configuration.timeout = 5 # Set timeout to 5 seconds
|
80
|
+
```
|
69
81
|
|
70
82
|
## Earth Tool API restrictions
|
71
83
|
|
@@ -112,8 +124,10 @@ The cache store can be any object that supports the following methods:
|
|
112
124
|
|
113
125
|
If you need to expire cached content:
|
114
126
|
|
115
|
-
|
116
|
-
|
127
|
+
```ruby
|
128
|
+
EarthTools.cache.expire("http://...") # Expire cached result for a URL
|
129
|
+
EarthTools.cache.expire(:all) # Expire all cached results
|
130
|
+
```
|
117
131
|
|
118
132
|
There is no need to include the prefix when passing a URL to be expired. Expiring `:all` will only expire keys with the configured prefix (won't kill every entry in your key/value store).
|
119
133
|
|
@@ -121,16 +135,16 @@ There is no need to include the prefix when passing a URL to be expired. Expirin
|
|
121
135
|
|
122
136
|
By default Earth Tools will rescue any exceptions raised by calls to the webservice and return an empty array (using warn() to inform you of the error). You can override this and implement custom error handling for certain exceptions by using the `:always_raise` option:
|
123
137
|
|
124
|
-
|
138
|
+
```ruby
|
139
|
+
EarthTools::Configuration.always_raise = [SocketError, TimeoutError]
|
140
|
+
```
|
125
141
|
|
126
142
|
## Issues & contributing
|
127
143
|
|
128
|
-
|
129
|
-
|
130
|
-
## Future
|
131
|
-
|
132
|
-
I would love to see this functionality brought into the `geocoder` gem or similar in the future.
|
144
|
+
Please post any issues to the [issues queue on github](https://github.com/mckramer/earth_tools/issues).
|
133
145
|
|
134
146
|
# License and attributions
|
135
147
|
|
136
|
-
This gem's structure and design borrows heavily from
|
148
|
+
This gem's structure and design borrows heavily from [geocoder](https://github.com/alexreisner/geocoder), so thanks to its author. This repository is released under the MIT license (see the [LICENSE](LICENSE) for full text).
|
149
|
+
|
150
|
+
Find me on twitter [@maxckramer](https://twitter.com/maxckramer).
|
@@ -28,7 +28,7 @@ module EarthTools
|
|
28
28
|
# See {http://en.wikipedia.org/wiki/Latitude}.
|
29
29
|
# @return [Float] the latitude
|
30
30
|
def latitude
|
31
|
-
@data['latitude'].to_f
|
31
|
+
@data['location']['latitude'].to_f
|
32
32
|
end
|
33
33
|
|
34
34
|
##
|
@@ -36,7 +36,7 @@ module EarthTools
|
|
36
36
|
# See {http://en.wikipedia.org/wiki/Longitude}.
|
37
37
|
# @return the longitude
|
38
38
|
def longitude
|
39
|
-
@data['longitude'].to_f
|
39
|
+
@data['location']['longitude'].to_f
|
40
40
|
end
|
41
41
|
|
42
42
|
##
|
data/lib/earth_tools/version.rb
CHANGED
data/test/cache_test.rb
CHANGED
@@ -16,7 +16,7 @@ class CacheTest < MiniTest::Unit::TestCase
|
|
16
16
|
def test_store_and_retrieve_from_cache
|
17
17
|
@cache['test/1'] = :data
|
18
18
|
|
19
|
-
assert_equal :data, @cache['test/1']
|
19
|
+
assert_equal :data, @cache['test/1']
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_remove_single_url
|
@@ -25,16 +25,16 @@ class CacheTest < MiniTest::Unit::TestCase
|
|
25
25
|
|
26
26
|
@cache.expire('test/1')
|
27
27
|
|
28
|
-
assert_nil @cache['test/1']
|
29
|
-
assert_equal :data, @cache['test/2']
|
28
|
+
assert_nil @cache['test/1']
|
29
|
+
assert_equal :data, @cache['test/2']
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_remove_all_prefixed_urls
|
33
33
|
@raw_cache['test'] = :data
|
34
34
|
@raw_cache['other:test'] = :data
|
35
|
-
@cache['test/1']
|
36
|
-
@cache['test/2']
|
37
|
-
@cache['test/3']
|
35
|
+
@cache['test/1'] = :data
|
36
|
+
@cache['test/2'] = :data
|
37
|
+
@cache['test/3'] = :data
|
38
38
|
|
39
39
|
@cache.expire(:all)
|
40
40
|
assert_equal :data, @raw_cache['test'], 'The cache should not affect non-prefixed entries.'
|
data/test/configuration_test.rb
CHANGED
@@ -7,45 +7,32 @@ class ConfigurationTest < MiniTest::Unit::TestCase
|
|
7
7
|
EarthTools::Configuration.set_defaults
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
def test_configurated_by_class_method
|
10
|
+
def test_configure_by_class_method
|
12
11
|
EarthTools::Configuration.units = :metric
|
13
|
-
assert_equal EarthTools::Configuration.units
|
12
|
+
assert_equal :metric, EarthTools::Configuration.units
|
13
|
+
|
14
14
|
result = EarthTools.height(52.4822, -1.8946)
|
15
|
-
|
16
|
-
assert_equal result.height, result.feet
|
17
|
-
else
|
18
|
-
refute_equal result.height, result.feet
|
19
|
-
end
|
15
|
+
refute_equal result.height, result.feet
|
20
16
|
end
|
21
17
|
|
22
|
-
|
23
|
-
def test_configuration
|
24
|
-
|
25
|
-
# DSL
|
18
|
+
def test_block_configuration
|
26
19
|
EarthTools.configure do |config|
|
27
20
|
config.units = :metric
|
28
21
|
end
|
22
|
+
assert_equal :metric, EarthTools::Configuration.units
|
29
23
|
|
30
|
-
assert_equal EarthTools::Configuration.units, :metric
|
31
24
|
result = EarthTools.height(52.4822, -1.8946)
|
32
|
-
|
33
|
-
assert_equal result.height, result.feet
|
34
|
-
else
|
35
|
-
refute_equal result.height, result.feet
|
36
|
-
end
|
25
|
+
refute_equal result.height, result.feet
|
37
26
|
|
38
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_property_configuration
|
39
30
|
EarthTools.configure.units = :metric
|
31
|
+
assert_equal :metric, EarthTools::Configuration.units
|
40
32
|
|
41
|
-
assert_equal EarthTools::Configuration.units, :metric
|
42
33
|
result = EarthTools.height(52.4822, -1.8946)
|
43
34
|
assert_equal result.height, result.meters
|
44
|
-
|
45
|
-
assert_equal result.height, result.feet
|
46
|
-
else
|
47
|
-
refute_equal result.height, result.feet
|
48
|
-
end
|
35
|
+
refute_equal result.height, result.feet
|
49
36
|
end
|
50
37
|
|
51
38
|
end
|
data/test/earth_tools_test.rb
CHANGED
@@ -12,15 +12,15 @@ require 'mock_lookup'
|
|
12
12
|
class EarthToolsTest < MiniTest::Unit::TestCase
|
13
13
|
|
14
14
|
def test_time_zone_method_returns_result_object
|
15
|
-
|
15
|
+
assert_instance_of EarthTools::Result::TimeZone, EarthTools.time_zone(40.71417, -74.00639)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_sunrise_sunset_method_returns_result_object
|
19
|
-
|
19
|
+
assert_instance_of EarthTools::Result::SunriseSunset, EarthTools.sunrise_sunset(40.71417, -74.00639, 12, 4)
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_height_method_returns_result_object
|
23
|
-
|
23
|
+
assert_instance_of EarthTools::Result::Height, EarthTools.height(52.4822, -1.8946)
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
File without changes
|
data/test/fixtures/{sun_(40.71417,-74.00639,4,12,99,0).xml → sun/40.71417,-74.00639,4,12,99,0.xml}
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
2
|
+
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone-1.1.xsd">
|
3
|
+
<version>1.1</version>
|
4
|
+
<location>
|
5
|
+
<latitude>40.71655</latitude>
|
6
|
+
<longitude>-12.12318</longitude>
|
7
|
+
</location>
|
8
|
+
<offset>-5</offset>
|
9
|
+
<suffix>R</suffix>
|
10
|
+
<localtime>14 Jun 2012 13:29:06</localtime>
|
11
|
+
<isotime>2012-06-14 13:29:06 -0500</isotime>
|
12
|
+
<utctime>2012-06-14 18:29:06</utctime>
|
13
|
+
<dst>True</dst>
|
14
|
+
</timezone>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
2
|
+
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone-1.1.xsd">
|
3
|
+
<version>1.1</version>
|
4
|
+
<location>
|
5
|
+
<latitude>40.71655</latitude>
|
6
|
+
<longitude>-12.12318</longitude>
|
7
|
+
</location>
|
8
|
+
<offset>-5</offset>
|
9
|
+
<suffix>R</suffix>
|
10
|
+
<localtime>14 Jun 2012 13:29:06</localtime>
|
11
|
+
<isotime>2012-06-14 13:29:06 -0500</isotime>
|
12
|
+
<utctime>2012-06-14 18:29:06</utctime>
|
13
|
+
<dst>False</dst>
|
14
|
+
</timezone>
|
data/test/height_test.rb
CHANGED
@@ -13,26 +13,22 @@ class HeightTest < MiniTest::Unit::TestCase
|
|
13
13
|
@result = EarthTools.height(52.4822, -1.8946)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
# @see configuration_test.rb for tests for height configuration
|
17
|
+
def test_height
|
18
|
+
assert_instance_of Float, @result.height
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_feet_parsed_correctly
|
27
|
-
assert_equal 462.6, @result.feet, 'Feet was not parsed correctly'
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_meters_is_float
|
31
|
-
assert @result.meters.is_a?(Float), 'Meters should be a float'
|
21
|
+
def test_feet
|
22
|
+
feet = @result.feet
|
23
|
+
assert_instance_of Float, feet
|
24
|
+
assert_equal 462.6, feet
|
32
25
|
end
|
33
26
|
|
34
|
-
def
|
35
|
-
|
27
|
+
def test_meters
|
28
|
+
meters = @result.meters
|
29
|
+
|
30
|
+
assert_instance_of Float, meters
|
31
|
+
assert_equal 141, meters
|
36
32
|
end
|
37
33
|
|
38
34
|
end
|
data/test/mock_lookup.rb
CHANGED
data/test/sunrise_sunset_test.rb
CHANGED
@@ -11,85 +11,164 @@ class SunriseSunsetTest < MiniTest::Unit::TestCase
|
|
11
11
|
|
12
12
|
def setup
|
13
13
|
@result = EarthTools.sunrise_sunset(40.71417, -74.00639, 12, 4)
|
14
|
+
@year = Time.now.year
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def test_location
|
18
|
+
assert_equal 40.71417, @result.latitude
|
19
|
+
assert_equal -74.00639, @result.longitude
|
20
|
+
assert_equal [40.71417, -74.00639], @result.location
|
21
|
+
end
|
19
22
|
|
20
23
|
def test_sunrise_is_time
|
21
|
-
|
24
|
+
sunrise = @result.sunrise
|
25
|
+
|
26
|
+
assert_instance_of Time, sunrise
|
27
|
+
assert_equal Time.new(@year, 12, 4, 7, 5, 50, '-05:00'), sunrise
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_sunset
|
31
|
+
sunset = @result.sunset
|
32
|
+
|
33
|
+
assert_instance_of Time, sunset
|
34
|
+
assert_equal Time.new(@year, 12, 4, 16, 26, 59, '-05:00'), sunset
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_twilight_as_morning_and_astronomical
|
38
|
+
morning_astronomical_twilight = @result.twilight(:morning, :astronomical)
|
39
|
+
|
40
|
+
assert_instance_of Time, morning_astronomical_twilight
|
41
|
+
assert_equal Time.new(@year, 12, 4, 5, 27, 39, '-05:00'), morning_astronomical_twilight
|
22
42
|
end
|
23
43
|
|
24
|
-
def
|
25
|
-
|
44
|
+
def test_twilight_as_morning_and_civil
|
45
|
+
morning_civil_twilight = @result.twilight(:morning, :civil)
|
46
|
+
|
47
|
+
assert_instance_of Time, morning_civil_twilight
|
48
|
+
assert_equal Time.new(@year, 12, 4, 6, 35, 6, '-05:00'), morning_civil_twilight
|
26
49
|
end
|
27
50
|
|
28
|
-
|
29
|
-
|
30
|
-
|
51
|
+
def test_twilight_as_morning_and_nautical
|
52
|
+
morning_nautical_twilight = @result.twilight(:morning, :nautical)
|
53
|
+
|
54
|
+
assert_instance_of Time, morning_nautical_twilight
|
55
|
+
assert_equal Time.new(@year, 12, 4, 6, 0, 50, '-05:00'), morning_nautical_twilight
|
56
|
+
end
|
31
57
|
|
32
|
-
def
|
33
|
-
|
58
|
+
def test_twilight_as_evening_and_astronomical
|
59
|
+
evening_astronomical_twilight = @result.twilight(:evening, :astronomical)
|
60
|
+
|
61
|
+
assert_instance_of Time, evening_astronomical_twilight
|
62
|
+
assert_equal Time.new(@year, 12, 4, 18, 5, 10, '-05:00'), evening_astronomical_twilight
|
34
63
|
end
|
35
64
|
|
36
|
-
def
|
37
|
-
|
65
|
+
def test_twilight_as_evening_and_civil
|
66
|
+
evening_civil_twilight = @result.twilight(:evening, :civil)
|
67
|
+
|
68
|
+
assert_instance_of Time, evening_civil_twilight
|
69
|
+
assert_equal Time.new(@year, 12, 4, 16, 57, 43, '-05:00'), evening_civil_twilight
|
38
70
|
end
|
39
71
|
|
40
|
-
|
41
|
-
|
42
|
-
|
72
|
+
def test_twilight_as_evening_and_nautical
|
73
|
+
evening_nautical_twilight = @result.twilight(:evening, :nautical)
|
74
|
+
|
75
|
+
assert_instance_of Time, evening_nautical_twilight
|
76
|
+
assert_equal Time.new(@year, 12, 4, 17, 31, 59, '-05:00'), evening_nautical_twilight
|
77
|
+
end
|
43
78
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
assert @result.twilight(:evening, :civil).is_a?(Time), 'Twilight should be a time'
|
50
|
-
assert @result.twilight(:evening, :nautical).is_a?(Time), 'Twilight should be a time'
|
79
|
+
def test_morning_twilight_as_astronomical
|
80
|
+
morning_astronomical_twilight = @result.morning_twilight(:astronomical)
|
81
|
+
|
82
|
+
assert_instance_of Time, morning_astronomical_twilight
|
83
|
+
assert_equal Time.new(@year, 12, 4, 5, 27, 39, '-05:00'), morning_astronomical_twilight
|
51
84
|
end
|
52
85
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
assert_equal Time.new(year, 12, 4, 6,
|
58
|
-
assert_equal Time.new(year, 12, 4, 18, 5, 10, '-05:00'), @result.twilight(:evening, :astronomical), 'Twilight was not parsed correctly'
|
59
|
-
assert_equal Time.new(year, 12, 4, 16, 57, 43, '-05:00'), @result.twilight(:evening, :civil), 'Twilight was not parsed correctly'
|
60
|
-
assert_equal Time.new(year, 12, 4, 17, 31, 59, '-05:00'), @result.twilight(:evening, :nautical), 'Twilight was not parsed correctly'
|
86
|
+
def test_morning_twilight_as_civil
|
87
|
+
morning_civil_twilight = @result.morning_twilight(:civil)
|
88
|
+
|
89
|
+
assert_instance_of Time, morning_civil_twilight
|
90
|
+
assert_equal Time.new(@year, 12, 4, 6, 35, 6, '-05:00'), morning_civil_twilight
|
61
91
|
end
|
62
92
|
|
63
|
-
|
64
|
-
|
65
|
-
|
93
|
+
def test_morning_twilight_as_nautical
|
94
|
+
morning_nautical_twilight = @result.morning_twilight(:nautical)
|
95
|
+
|
96
|
+
assert_instance_of Time, morning_nautical_twilight
|
97
|
+
assert_equal Time.new(@year, 12, 4, 6, 0, 50, '-05:00'), morning_nautical_twilight
|
98
|
+
end
|
66
99
|
|
67
|
-
|
68
|
-
|
69
|
-
|
100
|
+
def test_evening_twilight_as_astronomical
|
101
|
+
evening_astronomical_twilight = @result.evening_twilight(:astronomical)
|
102
|
+
|
103
|
+
assert_instance_of Time, evening_astronomical_twilight
|
104
|
+
assert_equal Time.new(@year, 12, 4, 18, 5, 10, '-05:00'), evening_astronomical_twilight
|
105
|
+
end
|
70
106
|
|
71
|
-
|
72
|
-
|
73
|
-
|
107
|
+
def test_evening_twilight_as_civil
|
108
|
+
evening_civil_twilight = @result.evening_twilight(:civil)
|
109
|
+
|
110
|
+
assert_instance_of Time, evening_civil_twilight
|
111
|
+
assert_equal Time.new(@year, 12, 4, 16, 57, 43, '-05:00'), evening_civil_twilight
|
112
|
+
end
|
74
113
|
|
75
|
-
def
|
76
|
-
|
114
|
+
def test_evening_twilight_as_nautical
|
115
|
+
evening_nautical_twilight = @result.evening_twilight(:nautical)
|
116
|
+
|
117
|
+
assert_instance_of Time, evening_nautical_twilight
|
118
|
+
assert_equal Time.new(@year, 12, 4, 17, 31, 59, '-05:00'), evening_nautical_twilight
|
77
119
|
end
|
78
120
|
|
79
|
-
def
|
80
|
-
|
121
|
+
def test_morning_astronomical_twilight
|
122
|
+
morning_astronomical_twilight = @result.morning_astronomical_twilight
|
123
|
+
|
124
|
+
assert_instance_of Time, morning_astronomical_twilight
|
125
|
+
assert_equal Time.new(@year, 12, 4, 5, 27, 39, '-05:00'), morning_astronomical_twilight
|
81
126
|
end
|
82
127
|
|
83
|
-
|
84
|
-
|
85
|
-
|
128
|
+
def test_morning_civil_twilight
|
129
|
+
morning_civil_twilight = @result.morning_civil_twilight
|
130
|
+
|
131
|
+
assert_instance_of Time, morning_civil_twilight
|
132
|
+
assert_equal Time.new(@year, 12, 4, 6, 35, 6, '-05:00'), morning_civil_twilight
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_morning_nautical_twilight
|
136
|
+
morning_nautical_twilight = @result.morning_nautical_twilight
|
137
|
+
|
138
|
+
assert_instance_of Time, morning_nautical_twilight
|
139
|
+
assert_equal Time.new(@year, 12, 4, 6, 0, 50, '-05:00'), morning_nautical_twilight
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_evening_astronomical_twilight
|
143
|
+
evening_astronomical_twilight = @result.evening_astronomical_twilight
|
144
|
+
|
145
|
+
assert_instance_of Time, evening_astronomical_twilight
|
146
|
+
assert_equal Time.new(@year, 12, 4, 18, 5, 10, '-05:00'), evening_astronomical_twilight
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_evening_civil_twilight
|
150
|
+
evening_civil_twilight = @result.evening_civil_twilight
|
151
|
+
|
152
|
+
assert_instance_of Time, evening_civil_twilight
|
153
|
+
assert_equal Time.new(@year, 12, 4, 16, 57, 43, '-05:00'), evening_civil_twilight
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_evening_nautical_twilight
|
157
|
+
evening_nautical_twilight = @result.evening_nautical_twilight
|
158
|
+
|
159
|
+
assert_instance_of Time, evening_nautical_twilight
|
160
|
+
assert_equal Time.new(@year, 12, 4, 17, 31, 59, '-05:00'), evening_nautical_twilight
|
161
|
+
end
|
86
162
|
|
87
|
-
def
|
88
|
-
|
163
|
+
def test_utc_offset
|
164
|
+
utc_offset = @result.utc_offset
|
165
|
+
|
166
|
+
assert_kind_of Integer, utc_offset
|
167
|
+
assert_equal -5, utc_offset
|
89
168
|
end
|
90
169
|
|
91
|
-
def
|
92
|
-
assert_equal
|
170
|
+
def test_version
|
171
|
+
assert_equal 1.0, @result.version
|
93
172
|
end
|
94
173
|
|
95
174
|
end
|
data/test/test_helper.rb
CHANGED
data/test/time_zone_test.rb
CHANGED
@@ -10,51 +10,63 @@ require 'mock_lookup'
|
|
10
10
|
class TimeZoneTest < MiniTest::Unit::TestCase
|
11
11
|
|
12
12
|
def setup
|
13
|
-
@result
|
13
|
+
@result = EarthTools.time_zone(40.71417, -74.00639)
|
14
|
+
@result2 = EarthTools.time_zone(40.71655, -12.12318)
|
15
|
+
@result3 = EarthTools.time_zone(50.21655, -54.87656)
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
+
def test_time_zone_returns_result
|
19
|
+
assert_instance_of EarthTools::Result::TimeZone, @result
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
|
22
|
+
def test_iso_time
|
23
|
+
iso_time = @result.iso_time
|
24
|
+
|
25
|
+
assert_instance_of Time, iso_time
|
26
|
+
assert_equal Time.new(2012, 6, 14, 13, 29, 6, '-05:00'), iso_time
|
22
27
|
end
|
23
28
|
|
24
|
-
def
|
25
|
-
|
29
|
+
def test_local_time
|
30
|
+
local_time = @result.local_time
|
31
|
+
|
32
|
+
assert_instance_of Time, local_time
|
33
|
+
assert_equal Time.new(2012, 6, 14, 13, 29, 6, '-05:00'), local_time
|
26
34
|
end
|
27
35
|
|
28
|
-
def
|
29
|
-
|
36
|
+
def test_suffix
|
37
|
+
suffix = @result.suffix
|
38
|
+
|
39
|
+
assert_instance_of String, suffix
|
40
|
+
assert_equal 'R', suffix
|
30
41
|
end
|
31
42
|
|
32
|
-
def
|
33
|
-
|
43
|
+
def test_utc_offset
|
44
|
+
utc_offset = @result.utc_offset
|
45
|
+
|
46
|
+
assert_kind_of Integer, utc_offset
|
47
|
+
assert_equal -5, utc_offset
|
34
48
|
end
|
35
49
|
|
36
|
-
def
|
37
|
-
|
50
|
+
def test_utc_time
|
51
|
+
utc_time = @result.utc_time
|
52
|
+
|
53
|
+
assert_instance_of Time, utc_time
|
54
|
+
assert_equal Time.utc(2012, 6, 14, 18, 29, 6), utc_time
|
38
55
|
end
|
39
56
|
|
40
|
-
def
|
41
|
-
assert_equal '
|
57
|
+
def test_dst_as_true
|
58
|
+
assert_equal 'True', @result2.dst
|
59
|
+
assert @result2.dst?
|
42
60
|
end
|
43
61
|
|
44
|
-
def
|
45
|
-
|
62
|
+
def test_dst_as_false
|
63
|
+
assert_equal 'False', @result3.dst
|
64
|
+
refute @result3.dst?
|
46
65
|
end
|
47
66
|
|
48
|
-
def
|
49
|
-
assert_equal
|
50
|
-
|
51
|
-
|
52
|
-
def test_utc_time_is_time
|
53
|
-
assert @result.utc_time.is_a?(Time), 'UTC time should be a time object'
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_utc_time_parsed_correctly
|
57
|
-
assert_equal Time.utc(2012, 6, 14, 18, 29, 6), @result.utc_time, 'UTC time was not parsed correctly'
|
67
|
+
def test_dst_as_unknown
|
68
|
+
assert_equal 'Unknown', @result.dst
|
69
|
+
assert_nil @result.dst?
|
58
70
|
end
|
59
71
|
|
60
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: earth_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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:
|
12
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.7.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: 1.7.3
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: xml-simple
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,9 +73,11 @@ files:
|
|
73
73
|
- test/cache_test.rb
|
74
74
|
- test/configuration_test.rb
|
75
75
|
- test/earth_tools_test.rb
|
76
|
-
- test/fixtures/
|
77
|
-
- test/fixtures/
|
78
|
-
- test/fixtures/
|
76
|
+
- test/fixtures/height/52.4822,-1.8946.xml
|
77
|
+
- test/fixtures/sun/40.71417,-74.00639,4,12,99,0.xml
|
78
|
+
- test/fixtures/timezone/40.71417,-74.00639.xml
|
79
|
+
- test/fixtures/timezone/40.71655,-12.12318.xml
|
80
|
+
- test/fixtures/timezone/50.21655,-54.87656.xml
|
79
81
|
- test/height_test.rb
|
80
82
|
- test/integration/height_smoke_test.rb
|
81
83
|
- test/integration/sunrise_sunset_smoke_test.rb
|
@@ -96,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
98
|
requirements:
|
97
99
|
- - ! '>='
|
98
100
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
101
|
+
version: 1.9.3
|
100
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
103
|
none: false
|
102
104
|
requirements:
|