Class: PrayerTimes::Calculator

Inherits:
Object
  • Object
show all
Includes:
Setters
Defined in:
lib/prayer_times/calculator.rb

Overview

This is main interface class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Setters

#calculation_method=, #invalid_time=, #iterations_count=, #time_format=, #time_suffixes=, #times_names=, #times_offsets=

Constructor Details

#initialize(calc_method, opts) ⇒ Calculator

Initializer

Parameters:

  • calc_method (String)

    the calculation method to use

  • opts (Hash)

    formatting options

Options Hash (opts):

  • :time_format (String)
  • :invalid_time (String)
  • :time_suffixes (String)
  • :times_names (String)
  • :times_offsets (String)
  • :iterations_count (String)

    this is algorithmic option. Don’t set it unless you know what you are doing

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/prayer_times/calculator.rb', line 19

def initialize(calc_method, opts)
  self.calculation_method = calc_method

  self.time_format = opts[:time_format]

  self.invalid_time = opts[:invalid_time]

  self.time_suffixes = (opts[:time_suffixes])

  self.times_names = (opts[:times_names])

  self.times_offsets = (opts[:times_offsets])

  self.iterations_count = opts[:iterations_count]
end

Instance Attribute Details

#calculation_methodObject (readonly)

Returns the value of attribute calculation_method.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def calculation_method
  @calculation_method
end

#invalid_timeObject (readonly)

Returns the value of attribute invalid_time.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def invalid_time
  @invalid_time
end

#iterations_countObject (readonly)

Returns the value of attribute iterations_count.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def iterations_count
  @iterations_count
end

#time_formatObject (readonly)

Returns the value of attribute time_format.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def time_format
  @time_format
end

#time_suffixesObject (readonly)

Returns the value of attribute time_suffixes.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def time_suffixes
  @time_suffixes
end

#times_namesObject (readonly)

Returns the value of attribute times_names.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def times_names
  @times_names
end

#times_offsetsObject (readonly)

Returns the value of attribute times_offsets.



7
8
9
# File 'lib/prayer_times/calculator.rb', line 7

def times_offsets
  @times_offsets
end

Instance Method Details

#get_times(date, coords, time_zone, dst = nil) ⇒ Hash

Gets the prayers times

Parameters:

  • date (Date)

    the date

  • coords (Array)

    of type [long, lat [,alt]]

  • time_zone (Integer)

    the time zone

  • dst (Integer) (defaults to: nil)

    Daylight saving time

Returns:

  • (Hash)

    times



43
44
45
46
47
48
49
# File 'lib/prayer_times/calculator.rb', line 43

def get_times(date, coords, time_zone, dst = nil)
  Calculation.new(self,
  date,
  coords,
  time_zone + (dst.nil? ? 0 : 1)).
  compute
end