Class: BritishSuntimes
- Inherits:
-
Object
- Object
- BritishSuntimes
- Defined in:
- lib/british_suntimes.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bst_end ⇒ Object
readonly
Returns the value of attribute bst_end.
-
#bst_start ⇒ Object
readonly
Returns the value of attribute bst_start.
-
#longest_day ⇒ Object
readonly
Returns the value of attribute longest_day.
-
#shortest_day ⇒ Object
readonly
Returns the value of attribute shortest_day.
-
#to_dx ⇒ Object
readonly
Returns the value of attribute to_dx.
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
Instance Method Summary collapse
-
#export(filename = @location + "-suntimes-#{@year}.txt") ⇒ Object
exports the sun times to a raw Dynarex file.
-
#initialize(year = Date.today.year.to_s, location: 'edinburgh', debug: false) ⇒ BritishSuntimes
constructor
A new instance of BritishSuntimes.
Constructor Details
#initialize(year = Date.today.year.to_s, location: 'edinburgh', debug: false) ⇒ BritishSuntimes
Returns a new instance of BritishSuntimes.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/british_suntimes.rb', line 21 def initialize(year=Date.today.year.to_s, location: 'edinburgh', debug: false) @location, @debug = location, debug a = (Date.parse(year + ' Jan')...Date.parse(year.succ + ' Jan')).to_a g = Geocoder.search(location) puts 'finding the times ...' if @debug times = a.inject({}) do |r, date| calc = SolarEventCalculator.new(date, *g[0].coordinates) a2 = %w(sunrise sunset).map do |event| calc.method('compute_utc_official_'.+(event).to_sym).call\ .strftime("%H:%M") end r.merge(date.strftime("%d %b") => a2) end # alter the times for British summertime @bst_start = ChronicCron.new('last sunday in March at 1am', Time.local(year)).to_date @bst_end = ChronicCron.new('last sunday in October at 2am', Time.local(year)).to_date (@bst_start...@bst_end).to_a.each do |d| t1, t2 = times[d.strftime("%d %b")].map {|x| Time.parse(x)} t1 += 60 * 60; t2 += 60 * 60 times[d.strftime("%d %b")] = [t1.strftime("%H:%M"), t2.strftime("%H:%M")] end @year, @location, @to_h = year, location, times puts 'buklding @to_dx' if @debug @to_dx = build_dx() end |
Instance Attribute Details
#bst_end ⇒ Object (readonly)
Returns the value of attribute bst_end.
18 19 20 |
# File 'lib/british_suntimes.rb', line 18 def bst_end @bst_end end |
#bst_start ⇒ Object (readonly)
Returns the value of attribute bst_start.
18 19 20 |
# File 'lib/british_suntimes.rb', line 18 def bst_start @bst_start end |
#longest_day ⇒ Object (readonly)
Returns the value of attribute longest_day.
18 19 20 |
# File 'lib/british_suntimes.rb', line 18 def longest_day @longest_day end |
#shortest_day ⇒ Object (readonly)
Returns the value of attribute shortest_day.
18 19 20 |
# File 'lib/british_suntimes.rb', line 18 def shortest_day @shortest_day end |
#to_dx ⇒ Object (readonly)
Returns the value of attribute to_dx.
18 19 20 |
# File 'lib/british_suntimes.rb', line 18 def to_dx @to_dx end |
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
18 19 20 |
# File 'lib/british_suntimes.rb', line 18 def to_h @to_h end |
Instance Method Details
#export(filename = @location + "-suntimes-#{@year}.txt") ⇒ Object
exports the sun times to a raw Dynarex file
64 65 66 |
# File 'lib/british_suntimes.rb', line 64 def export(filename=@location + "-suntimes-#{@year}.txt") File.write filename, @to_dx.to_s end |