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.
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  Find the changes below for each version.
3
3
 
4
+ ## 0.1.1
5
+ * Upgrade `rest-client` to resolve security issue (OSVDB-117461) in dependency
6
+ * Fix tests
7
+ * Add coveralls
8
+ * Drop support for ruby 1.9.2
9
+
4
10
  ## 0.1.0
5
11
  * Add cache handling
6
12
 
data/Gemfile CHANGED
@@ -1,3 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
4
+
5
+ gem "rake"
6
+
7
+ group :test do
8
+ if ENV["CI"]
9
+ gem "coveralls", require: false
10
+ end
11
+ end
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.9.3
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
- `gem 'earth_tools'`
16
+ ```ruby
17
+ gem 'earth_tools'
18
+ ```
17
19
 
18
- and then bundle your gemfile:
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
- # API
31
- result = EarthTools.time_zone(latitude, longitude)
32
- # Example
33
- result = EarthTools.time_zone(40.71417, -74.00639) # New York City
34
- result.iso_time # => 2012-06-14 12:56:40 -0500
35
- result.utc_offset # => -5
36
- result.utc_time # => 2012-06-14 17:56:40 +0000
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
- # API
41
- result = EarthTools.height(latitude, longitude)
42
- # Example
43
- result = EarthTools.height(52.4822, -1.8946) # Birmingham, AL
44
- result.meters # => 141
45
- result.feet # => 462.6
46
- result.height # => 462.6 (when EarthTools::Configuration.units is set to :english units)
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
- # API
51
- result = EarthTools.sunrise_sunset(latitude, longitude, month, day, timezone, dst)
52
- # Example
53
- result = EarthTools.sunrise_sunset(40.71417, -74.00639, 12, 4, -5, 0) # New York City, December 4th
54
- result.sunrise # => 2012-12-04 07:05:50 -0500
55
- result.sunset # => 2012-12-04 16:26:59 -0500
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
- # Configure block (set to defaults)
60
- EarthTools.configure do |config|
61
- config.always_raise = [] # Add any errors that you would like to be custom handled, see "Error handling" section below
62
- config.cache = nil # Cache object (see Caching section for what methods are required)
63
- config.cache_prefix = "earth_tools:" # Prefix to use for cache keys
64
- config.timeout = 3 # Timeout in seconds
65
- config.units = :english # Also, can specify :metric
66
- end
67
- # Static call
68
- EarthTools::Configuration.timeout = 5 # Set timeout to 5 seconds
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
- EarthTools.cache.expire("http://...") # Expire cached result for a URL
116
- EarthTools.cache.expire(:all) # Expire all cached results
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
- EarthTools::Configuration.always_raise = [SocketError, TimeoutError]
138
+ ```ruby
139
+ EarthTools::Configuration.always_raise = [SocketError, TimeoutError]
140
+ ```
125
141
 
126
142
  ## Issues & contributing
127
143
 
128
- No outstanding issues right now. Please post any issues to the [issues queue on github](https://github.com/mckramer/earth_tools/issues).
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 `geocoder`, so thanks to its author. Find me on twitter [@maxckramer](https://twitter.com/maxckramer).
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
  ##
@@ -19,7 +19,7 @@ module EarthTools::Result
19
19
  # Whether or not the {#local_time} and {#iso_time} is currently in DST
20
20
  # @return [boolean] true || false || nil
21
21
  def dst?
22
- case @data['dst']
22
+ case dst
23
23
  when 'True' then
24
24
  true
25
25
  when 'False'
@@ -1,4 +1,4 @@
1
1
  module EarthTools
2
2
  # The gem version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
@@ -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'], 'The cache was not stored properly.'
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'], 'The cache should have deleted entry.'
29
- assert_equal :data, @cache['test/2'], 'The cache should not have deleted entry.'
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'] = :data
36
- @cache['test/2'] = :data
37
- @cache['test/3'] = :data
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.'
@@ -7,45 +7,32 @@ class ConfigurationTest < MiniTest::Unit::TestCase
7
7
  EarthTools::Configuration.set_defaults
8
8
  end
9
9
 
10
- # --- class method configuration ---
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, :metric
12
+ assert_equal :metric, EarthTools::Configuration.units
13
+
14
14
  result = EarthTools.height(52.4822, -1.8946)
15
- if result.height == 0
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
- # --- EarthTools#configure distances configuration ---
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
- if result.height == 0
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
- # Direct
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
- if result.height == 0
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
@@ -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
- assert EarthTools.time_zone(40.71417, -74.00639).is_a?(EarthTools::Result::TimeZone)
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
- assert EarthTools.sunrise_sunset(40.71417, -74.00639, 12, 4).is_a?(EarthTools::Result::SunriseSunset)
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
- assert EarthTools.height(52.4822, -1.8946).is_a?(EarthTools::Result::Height)
23
+ assert_instance_of EarthTools::Result::Height, EarthTools.height(52.4822, -1.8946)
24
24
  end
25
25
 
26
26
  end
@@ -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>
@@ -13,26 +13,22 @@ class HeightTest < MiniTest::Unit::TestCase
13
13
  @result = EarthTools.height(52.4822, -1.8946)
14
14
  end
15
15
 
16
- def test_height_is_float
17
- assert @result.height.is_a?(Float), 'Height should be a float'
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
- # Tests for height configuration in configuration_test.rb
21
-
22
- def test_feet_is_float
23
- assert @result.feet.is_a?(Float), 'Feet should be a float'
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 test_meters_parsed_correctly
35
- assert_equal 141, @result.meters, 'Meters was not parsed correctly'
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
@@ -16,7 +16,7 @@ class EarthTools::Lookup::Base
16
16
  #
17
17
  def retrieve(query)
18
18
  query = query.split('/')
19
- read_fixture "#{ query[3] }_(#{ query[4, query.size-1].join(',') }).xml"
19
+ read_fixture "#{ query[3] }/#{ query[4, query.size-1].join(',') }.xml"
20
20
  end
21
21
 
22
22
  end
@@ -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
- # sunrise
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
- assert @result.sunrise.is_a?(Time), 'Sunrise should be a time'
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 test_sunrise_parsed_correctly
25
- assert_equal Time.new(Time.now.year, 12, 4, 7, 5, 50, '-05:00'), @result.sunrise, 'Sunrise was not parsed correctly'
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
- # sunset
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 test_sunset_is_time
33
- assert @result.sunset.is_a?(Time), 'Sunset should be a time'
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 test_sunset_parsed_correctly
37
- assert_equal Time.new(Time.now.year, 12, 4, 16, 26, 59, '-05:00'), @result.sunset, 'Sunset was not parsed correctly'
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
- # twilight :time, :type
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 test_twilight_is_time
45
- assert @result.twilight(:morning, :astronomical).is_a?(Time), 'Twilight should be a time'
46
- assert @result.twilight(:morning, :civil).is_a?(Time), 'Twilight should be a time'
47
- assert @result.twilight(:morning, :nautical).is_a?(Time), 'Twilight should be a time'
48
- assert @result.twilight(:evening, :astronomical).is_a?(Time), 'Twilight should be a time'
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 test_twilight_parsed_correctly
54
- year = Time.now.year
55
- assert_equal Time.new(year, 12, 4, 5, 27, 39, '-05:00'), @result.twilight(:morning, :astronomical), 'Twilight was not parsed correctly'
56
- assert_equal Time.new(year, 12, 4, 6, 35, 6, '-05:00'), @result.twilight(:morning, :civil), 'Twilight was not parsed correctly'
57
- assert_equal Time.new(year, 12, 4, 6, 0, 50, '-05:00'), @result.twilight(:morning, :nautical), 'Twilight was not parsed correctly'
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
- # morning_twilight :type
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
- # evening_twilight :type
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
- # *_*_twilight
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 test_morning_astronomical_twilight_is_time
76
- assert @result.morning_astronomical_twilight.is_a?(Time), 'Morning astronomical twilight should be a time'
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 test_morning_astronomical_twilight_parsed_correctly
80
- assert_equal Time.new(Time.now.year, 12, 4, 5, 27, 39, '-05:00'), @result.morning_astronomical_twilight, 'Twilight was not parsed correctly'
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
- # utc_offset
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 test_utc_offset_is_integer
88
- assert @result.utc_offset.is_a?(Integer), 'UTC offset should be an integer'
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 test_utc_offset_parsed_correctly
92
- assert_equal -5, @result.utc_offset, 'UTC offset was not parsed correctly'
170
+ def test_version
171
+ assert_equal 1.0, @result.version
93
172
  end
94
173
 
95
174
  end
@@ -1,4 +1,9 @@
1
- require 'rubygems'
1
+ if ENV["CI"]
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
5
+
6
+ require 'rubygems'
2
7
  require 'minitest/autorun'
3
8
 
4
9
  require 'earth_tools/configuration'
@@ -10,51 +10,63 @@ require 'mock_lookup'
10
10
  class TimeZoneTest < MiniTest::Unit::TestCase
11
11
 
12
12
  def setup
13
- @result = EarthTools.time_zone(40.71417, -74.00639)
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 test_time_zone_method_returns_result_object
17
- assert @result.is_a?(EarthTools::Result::TimeZone), 'Result should be a time zone object'
18
+ def test_time_zone_returns_result
19
+ assert_instance_of EarthTools::Result::TimeZone, @result
18
20
  end
19
21
 
20
- def test_iso_time_is_time
21
- assert @result.iso_time.is_a?(Time), 'ISO time should be a time object'
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 test_iso_time_parsed_correctly
25
- assert_equal Time.new(2012, 6, 14, 13, 29, 6, '-05:00'), @result.iso_time, 'ISO time was not parsed correctly'
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 test_local_time_is_time
29
- assert @result.local_time.is_a?(Time), 'Local time should be a time object'
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 test_local_time_parsed_correctly
33
- assert_equal Time.new(2012, 6, 14, 13, 29, 6, '-05:00'), @result.local_time, 'Local time was not parsed correctly'
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 test_suffix_is_string
37
- assert @result.suffix.is_a?(String), 'Suffix should be a string'
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 test_suffix_parsed_correctly
41
- assert_equal 'R', @result.suffix, 'Suffix was not parsed correctly'
57
+ def test_dst_as_true
58
+ assert_equal 'True', @result2.dst
59
+ assert @result2.dst?
42
60
  end
43
61
 
44
- def test_utc_offset_is_integer
45
- assert @result.utc_offset.is_a?(Integer), 'UTC offset should be an integer'
62
+ def test_dst_as_false
63
+ assert_equal 'False', @result3.dst
64
+ refute @result3.dst?
46
65
  end
47
66
 
48
- def test_utc_offset_parsed_correctly
49
- assert_equal -5, @result.utc_offset, 'UTC offset was not parsed correctly'
50
- end
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.0
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: 2013-12-28 00:00:00.000000000 Z
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.6.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.6.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/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
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: '0'
101
+ version: 1.9.3
100
102
  required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  none: false
102
104
  requirements: