Skip to content
Browse files

Prefer instance methods to class methods.

* Update README to give an example using an instance method,
* Add spec for deprecated class method,
* Call the public set and rise methods from the class methods (closes
  #6).
  • Loading branch information...
1 parent 9c373b3 commit e25d596e7093f0ab0a7db9a482c3daf2a52166b3 @joeyates committed Feb 20, 2014
Showing with 21 additions and 7 deletions.
  1. +1 −1 README.md
  2. +2 −2 lib/sun_times.rb
  3. +18 −4 spec/unit/ruby_sun_times_spec.rb
View
2 README.md
@@ -38,7 +38,7 @@ There are two helper methods: 'rise' and 'set'.
day = Date.new(2010, 3, 8)
latitude = 43.779
longitude = 11.432
-puts SunTimes.set(day, latitude, longitude)
+puts SunTimes.new.set(day, latitude, longitude)
```
# References
View
4 lib/sun_times.rb
@@ -34,12 +34,12 @@ class SunTimes
# Deprecated: use SunTimes.new.rise(...)
def self.rise(date, latitude, longitude, options = {})
- new(options).calculate(:rise, date, latitude, longitude, options)
+ new(options).rise(date, latitude, longitude)
end
# Deprecated: use SunTimes.new.set(...)
def self.set(date, latitude, longitude, options = {})
- new(options).calculate(:set, date, latitude, longitude, options)
+ new(options).set(date, latitude, longitude)
end
# Deprecated: use SunTimes.new.rise/set(...)
View
22 spec/unit/ruby_sun_times_spec.rb
@@ -5,6 +5,8 @@
let(:day) { Date.new(2010, 3, 8) }
let(:latitude) { 43.779 }
let(:longitude) { 11.432 }
+ let(:set) { Time.gm(2010, 3, 8, 17, 11, 16) }
+ let(:rise) { Time.gm(2010, 3, 8, 5, 39, 53) }
let(:midsummer) { Date.new(2010, 6, 21) }
let(:midwinter) { Date.new(2010, 12, 21) }
let(:north_cape_latitude) { 71.170219 }
@@ -79,9 +81,23 @@
end
end
- describe '#rise' do
- let(:rise) { Time.gm(2010, 3, 8, 5, 39, 53) }
+ # SunTimes.rise is deprecated, use Suntimes.new.set
+ describe '.rise' do
+ it 'returns the sunrise time' do
+ result = described_class.rise(day, latitude, longitude)
+ expect(result).to be_within(1).of(rise)
+ end
+ end
+
+ # SunTimes.set is deprecated, use Suntimes.new.set
+ describe '.set' do
+ it 'returns the sunset time' do
+ result = described_class.set(day, latitude, longitude)
+ expect(result).to be_within(1).of(set)
+ end
+ end
+ describe '#rise' do
it 'returns the sunrise time' do
result = subject.rise(day, latitude, longitude)
expect(result).to be_within(1).of(rise)
@@ -97,8 +113,6 @@
end
describe '#set' do
- let(:set) { Time.gm(2010, 3, 8, 17, 11, 16) }
-
it 'returns the sunset time' do
result = subject.set(day, latitude, longitude)
expect(result).to be_within(1).of(set)

0 comments on commit e25d596

Please sign in to comment.
Something went wrong with that request. Please try again.