prayer_times 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +14 -0
- data/README.md +81 -0
- data/Rakefile +11 -0
- data/lib/prayer_times/calculation.rb +236 -0
- data/lib/prayer_times/calculation_method.rb +85 -0
- data/lib/prayer_times/calculation_methods.rb +144 -0
- data/lib/prayer_times/calculator.rb +57 -0
- data/lib/prayer_times/constants.rb +51 -0
- data/lib/prayer_times/math_helpers.rb +55 -0
- data/lib/prayer_times/setters.rb +71 -0
- data/lib/prayer_times/version.rb +4 -0
- data/lib/prayer_times.rb +41 -0
- data/prayer_times.gemspec +23 -0
- data/test/lib/prayer_times/calculation_method_test.rb +57 -0
- data/test/lib/prayer_times/calculation_methods_test.rb +39 -0
- data/test/lib/prayer_times/calculation_test.rb +123 -0
- data/test/lib/prayer_times/calculator_test.rb +16 -0
- data/test/lib/prayer_times/math_helpers_test.rb +46 -0
- data/test/lib/prayer_times/prayer_times_test.rb +23 -0
- data/test/lib/prayer_times/setters_test.rb +105 -0
- data/test/lib/prayer_times/version_test.rb +9 -0
- data/test/test_helper.rb +9 -0
- metadata +106 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module PrayerTimes
|
2
|
+
# General constants. Don't try to change their values.
|
3
|
+
# You have flexible general and instance configurations.
|
4
|
+
module Constants
|
5
|
+
# Used internally in the algorithm. Don't change unless you know
|
6
|
+
# What you are doing
|
7
|
+
# 0 < iterations_count < 6
|
8
|
+
@iterations_count = 1
|
9
|
+
|
10
|
+
# Determines the accepted values for iterations count
|
11
|
+
@accepted_iterations_count_range = 1..5
|
12
|
+
|
13
|
+
# Times names to be displayed
|
14
|
+
@times_names = {
|
15
|
+
imsak: 'Imsak',
|
16
|
+
fajr: 'Fajr',
|
17
|
+
sunrise: 'Sunrise',
|
18
|
+
dhuhr: 'Dhuhr',
|
19
|
+
asr: 'Asr',
|
20
|
+
sunset: 'Sunset',
|
21
|
+
maghrib: 'Maghrib',
|
22
|
+
isha: 'Isha',
|
23
|
+
midnight: 'Midnight'
|
24
|
+
}
|
25
|
+
|
26
|
+
# The option time_format takes the following values:
|
27
|
+
# '24h': 24-hour format,
|
28
|
+
# '12h': 12-hour format,
|
29
|
+
# '12hNS': 12-hour format with no suffix,
|
30
|
+
# 'Float': floating point number
|
31
|
+
@time_format = '24h'
|
32
|
+
|
33
|
+
# Determines the accepted time format values
|
34
|
+
@accepted_time_formats = ['12h','24h','12hNS','Float']
|
35
|
+
|
36
|
+
# Times suffixes names to be displayed
|
37
|
+
@time_suffixes= {:am => 'AM', :pm => 'PM'}
|
38
|
+
|
39
|
+
# What to display when the time is invalid
|
40
|
+
@invalid_time= '-----'
|
41
|
+
|
42
|
+
# Time offsets
|
43
|
+
@times_offsets = @times_names.keys.inject({}){ |h,k| h.merge!(k => 0)}
|
44
|
+
|
45
|
+
class << self
|
46
|
+
attr_reader :iterations_count, :times_names,
|
47
|
+
:time_format, :time_suffixes,:times_offsets,:invalid_time,
|
48
|
+
:accepted_iterations_count_range, :accepted_time_formats
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module PrayerTimes
|
2
|
+
# Math helpers module
|
3
|
+
module MathHelpers
|
4
|
+
# Calculates radians from degrees
|
5
|
+
# @param [Float] x
|
6
|
+
# @return [Float]
|
7
|
+
def radians(x) ; x * Math::PI/180 ; end
|
8
|
+
|
9
|
+
# Calculates degrees from radians
|
10
|
+
# @param [Float] x
|
11
|
+
# @return [Float]
|
12
|
+
def degrees(x) ; x * 180/Math::PI ; end
|
13
|
+
|
14
|
+
# Calculates sin in radians
|
15
|
+
# @param [Float] x
|
16
|
+
# @return [Float]
|
17
|
+
def rsin(x); Math.sin(radians x) ; end
|
18
|
+
|
19
|
+
# Calculates cos in radians
|
20
|
+
# @param [Float] x
|
21
|
+
# @return [Float]
|
22
|
+
def rcos(x); Math.cos(radians x) ; end
|
23
|
+
|
24
|
+
# Calculates tan in radians
|
25
|
+
# @param [Float] x
|
26
|
+
# @return [Float]
|
27
|
+
def rtan(x); Math.tan(radians x) ; end
|
28
|
+
|
29
|
+
# Calculates arcsin in degrees
|
30
|
+
# @param [Float] x
|
31
|
+
# @return [Float]
|
32
|
+
def darcsin(x); degrees Math.asin(x) ; end
|
33
|
+
|
34
|
+
# Calculates arccos in degrees
|
35
|
+
# @param [Float] x
|
36
|
+
# @return [Float]
|
37
|
+
def darccos(x); degrees Math.acos(x) ; end
|
38
|
+
|
39
|
+
# Calculates arctan in degrees
|
40
|
+
# @param [Float] x
|
41
|
+
# @return [Float]
|
42
|
+
def darctan(x); degrees Math.atan(x) ; end
|
43
|
+
|
44
|
+
# Calculates arccot in degrees
|
45
|
+
# @param [Float] x
|
46
|
+
# @return [Float]
|
47
|
+
def darccot(x); degrees Math.atan(1.0/x) ; end
|
48
|
+
|
49
|
+
# Calculates arctan2 in degrees
|
50
|
+
# @param [Float] x
|
51
|
+
# @param [Float] y
|
52
|
+
# @return [Float]
|
53
|
+
def darctan2(y, x); degrees Math.atan2(y, x) ; end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module PrayerTimes
|
2
|
+
# General setters
|
3
|
+
module Setters
|
4
|
+
|
5
|
+
# Sets iterations c
|
6
|
+
# @param [Integer] num
|
7
|
+
# 0 < num < 6
|
8
|
+
def iterations_count=(num)
|
9
|
+
@iterations_count = if (Constants.accepted_iterations_count_range).include?(num)
|
10
|
+
num
|
11
|
+
else
|
12
|
+
const_class.iterations_count
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets time format
|
17
|
+
# @param [String] format
|
18
|
+
# '24h': 24-hour format,
|
19
|
+
# '12h': 12-hour format,
|
20
|
+
# '12hNS': 12-hour format with no suffix,
|
21
|
+
# 'Float': floating point number
|
22
|
+
def time_format=(format)
|
23
|
+
@time_format = if Constants.accepted_time_formats.include?(format)
|
24
|
+
format
|
25
|
+
else
|
26
|
+
const_class.time_format
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sets the invalid time replacement string
|
31
|
+
# @param [String] str
|
32
|
+
def invalid_time=(str)
|
33
|
+
@invalid_time = str || const_class.invalid_time
|
34
|
+
end
|
35
|
+
|
36
|
+
# Sets times suffixes
|
37
|
+
# @param [Hash] suffixes
|
38
|
+
def time_suffixes=(suffixes)
|
39
|
+
s = suffixes.reject{|k,v| !(const_class.time_suffixes.key?(k) and v.is_a?(String))} rescue {}
|
40
|
+
@time_suffixes = const_class.time_suffixes.merge(s)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Sets times names
|
44
|
+
# @param [Hash] names
|
45
|
+
def times_names=(names)
|
46
|
+
s = names.reject{|k,v| !(const_class.times_names.key?(k) and v.is_a?(String))} rescue {}
|
47
|
+
@times_names = const_class.times_names.merge(s)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets times offsets
|
51
|
+
# @param [Hash] offsets
|
52
|
+
def times_offsets=(offsets)
|
53
|
+
s = offsets.reject{|k,v| !(const_class.times_offsets.key?(k) and v.is_a?(Numeric))} rescue {}
|
54
|
+
@times_offsets = const_class.times_offsets.merge(s)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Sets calculation method and the corresponding settings
|
58
|
+
# @param [String] calc_method the method name
|
59
|
+
def calculation_method=(calc_method)
|
60
|
+
@calculation_method = if PrayerTimes.calculation_methods.key?(calc_method)
|
61
|
+
const_class.calculation_methods[calc_method]
|
62
|
+
else
|
63
|
+
PrayerTimes.calculation_method
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def const_class #:nodoc:
|
68
|
+
raise "Please override this method"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/prayer_times.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'forwardable'
|
3
|
+
require_relative "prayer_times/version"
|
4
|
+
require_relative "prayer_times/constants"
|
5
|
+
require_relative "prayer_times/math_helpers"
|
6
|
+
require_relative "prayer_times/calculation_method"
|
7
|
+
require_relative "prayer_times/calculation_methods"
|
8
|
+
require_relative "prayer_times/setters"
|
9
|
+
require_relative "prayer_times/calculator"
|
10
|
+
require_relative "prayer_times/calculation"
|
11
|
+
|
12
|
+
module PrayerTimes #:nodoc:
|
13
|
+
class << self
|
14
|
+
include Setters
|
15
|
+
|
16
|
+
attr_reader :iterations_count, :times_names, :calculation_methods,
|
17
|
+
:calculation_method,:time_format, :time_suffixes,:times_offsets,
|
18
|
+
:invalid_time
|
19
|
+
# @see Calculator initializer
|
20
|
+
def new(calc_method=@calucation_method,opts={})
|
21
|
+
PrayerTimes::Calculator.new(calc_method, opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def const_class
|
25
|
+
Constants
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_attributes
|
29
|
+
attrs = [:iterations_count, :times_names, :time_format,
|
30
|
+
:time_suffixes,:times_offsets, :invalid_time]
|
31
|
+
attrs.each {|attr| self.send "#{attr}=", nil}
|
32
|
+
|
33
|
+
@calculation_methods = CalculationMethods.new
|
34
|
+
|
35
|
+
@calculation_method = @calculation_methods['MWL']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
set_attributes
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'prayer_times/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "prayer_times"
|
8
|
+
spec.version = PrayerTimes::VERSION
|
9
|
+
spec.authors = ["Khaled alHabache"]
|
10
|
+
spec.email = ["khellls@gmail.com"]
|
11
|
+
spec.description = %q{Calculates Muslim prayers times in given settings}
|
12
|
+
spec.summary = %q{Muslim prayers times calculator}
|
13
|
+
spec.homepage = "https://github.com/Startappz/prayer_times/"
|
14
|
+
spec.license = "GNU LGPL v3.0"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe PrayerTimes::CalculationMethod do
|
4
|
+
|
5
|
+
let(:name){"Medina"}
|
6
|
+
let(:description){"Medina testing methods"}
|
7
|
+
|
8
|
+
describe "Object" do
|
9
|
+
subject{PrayerTimes::CalculationMethod.new(name, description,{})}
|
10
|
+
it {subject.must_respond_to :description}
|
11
|
+
it {subject.must_respond_to :description=}
|
12
|
+
it {subject.must_respond_to :settings}
|
13
|
+
it {subject.must_respond_to :settings=}
|
14
|
+
it {subject.must_respond_to :offsets}
|
15
|
+
it {subject.must_respond_to :offsets=}
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#initialize" do
|
19
|
+
context "when name and description are provided" do
|
20
|
+
subject{PrayerTimes::CalculationMethod.new(name, description)}
|
21
|
+
it {subject.name.must_equal(name)}
|
22
|
+
it {subject.description.must_equal(description)}
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when settings are not provided" do
|
26
|
+
subject{PrayerTimes::CalculationMethod.new(name, description, {})}
|
27
|
+
it {subject.settings.must_equal(PrayerTimes::CalculationMethod.default_settings)}
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when settings are provided" do
|
31
|
+
let(:opts){{
|
32
|
+
fajr: 18,
|
33
|
+
asr: 'Hanafi',
|
34
|
+
isha: 18
|
35
|
+
}}
|
36
|
+
subject{PrayerTimes::CalculationMethod.new(name, description,opts)}
|
37
|
+
it {subject.settings.must_equal(PrayerTimes::CalculationMethod.default_settings.merge opts)}
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when offsets are not provided" do
|
41
|
+
subject{PrayerTimes::CalculationMethod.new(name, description, {}, {})}
|
42
|
+
it {subject.offsets.must_equal(PrayerTimes::Constants.times_offsets)}
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when offsets are provided" do
|
46
|
+
let(:opts){{
|
47
|
+
fajr: 3,
|
48
|
+
asr: -1,
|
49
|
+
isha: 6
|
50
|
+
}}
|
51
|
+
subject{PrayerTimes::CalculationMethod.new(name, description,{},opts)}
|
52
|
+
it {subject.offsets.must_equal(PrayerTimes::Constants.times_offsets.merge opts)}
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe PrayerTimes::CalculationMethods do
|
4
|
+
describe "#initialize" do
|
5
|
+
subject{PrayerTimes::CalculationMethods.new}
|
6
|
+
it {subject.must_respond_to :add}
|
7
|
+
it {subject.keys.must_equal subject.class.default_methods.keys}
|
8
|
+
it {subject.must_respond_to :[]}
|
9
|
+
it {subject.must_respond_to :each}
|
10
|
+
it {subject.must_respond_to :keys}
|
11
|
+
it {subject.must_respond_to :key?}
|
12
|
+
it {subject.must_respond_to :delete}
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
describe "#add" do
|
18
|
+
before do
|
19
|
+
@subject = PrayerTimes::CalculationMethods.new
|
20
|
+
@settings = {fajr: 16.5, asr: 'Hanafi', isha: '80 min'}
|
21
|
+
@offsets = {dhuhr: 2, asr: -1, isha: 3}
|
22
|
+
|
23
|
+
@new = @subject.add("Test", "Testing method", @settings, @offsets)
|
24
|
+
end
|
25
|
+
it {@new.must_be_instance_of PrayerTimes::CalculationMethod}
|
26
|
+
it {@subject["Test"].must_be_same_as @new}
|
27
|
+
it {@subject["Test"].settings[:fajr].must_equal 16.5}
|
28
|
+
it {@subject["Test"].settings[:asr].must_equal 'Hanafi'}
|
29
|
+
it {@subject["Test"].settings[:isha].must_equal '80 min'}
|
30
|
+
it {@subject["Test"].offsets[:dhuhr].must_equal 2}
|
31
|
+
it {@subject["Test"].offsets[:asr].must_equal -1}
|
32
|
+
it {@subject["Test"].offsets[:isha].must_equal 3}
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#names" do
|
36
|
+
subject{PrayerTimes::CalculationMethods.new}
|
37
|
+
it{subject.names.must_equal subject.keys}
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
# Those results are tested against numbers from the js code
|
4
|
+
# http://praytimes.org/code/v2/js/PrayTimes.js
|
5
|
+
describe PrayerTimes::Calculation do
|
6
|
+
describe '#compute' do
|
7
|
+
context 'when method is MWL' do
|
8
|
+
context 'when date is 2011/2/9, location is Waterloo/Canada and timezone -5' do
|
9
|
+
let(:pt){PrayerTimes.new}
|
10
|
+
subject{pt.get_times([2011,2,9], [43, -80], -5)}
|
11
|
+
let(:expected){{
|
12
|
+
'Imsak' => '05:40',
|
13
|
+
'Fajr' => '05:50',
|
14
|
+
'Sunrise' => '07:26',
|
15
|
+
'Dhuhr' => '12:34',
|
16
|
+
'Asr' => '15:18' ,
|
17
|
+
'Sunset' => '17:43' ,
|
18
|
+
'Maghrib' => '17:43' ,
|
19
|
+
'Isha' => '19:14' ,
|
20
|
+
'Midnight' => '00:35' }}
|
21
|
+
it{subject.must_equal expected}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when method is Makkah' do
|
26
|
+
let(:method_name){'Makkah'}
|
27
|
+
|
28
|
+
context 'time format is 24h and other settings are default' do
|
29
|
+
context 'when date is 2013/12/16, location is Amman/Jordan and timezone 3' do
|
30
|
+
let(:pt){PrayerTimes.new method_name}
|
31
|
+
subject{pt.get_times([2013,12,16], [31,36], 3)}
|
32
|
+
let(:expected){{
|
33
|
+
'Imsak' => '05:48',
|
34
|
+
'Fajr' => '05:58',
|
35
|
+
'Sunrise' => '07:27',
|
36
|
+
'Dhuhr' => '12:32',
|
37
|
+
'Asr' => '15:18' ,
|
38
|
+
'Sunset' => '17:36' ,
|
39
|
+
'Maghrib' => '17:36' ,
|
40
|
+
'Isha' => '19:06' ,
|
41
|
+
'Midnight' => '00:32' }}
|
42
|
+
it{subject.must_equal expected}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'time format is 24h, offsets are custom and other settings are default' do
|
47
|
+
context 'when date is 2013/12/16, location is Amman/Jordan and timezone 3' do
|
48
|
+
let(:pt){PrayerTimes.new method_name, times_offsets: {fajr: 4, dhuhr: 2, midnight: 1}}
|
49
|
+
subject{pt.get_times([2013,12,16], [31,36], 3)}
|
50
|
+
let(:expected){{
|
51
|
+
'Imsak' => '05:48',
|
52
|
+
'Fajr' => '06:02',
|
53
|
+
'Sunrise' => '07:27',
|
54
|
+
'Dhuhr' => '12:34',
|
55
|
+
'Asr' => '15:18' ,
|
56
|
+
'Sunset' => '17:36' ,
|
57
|
+
'Maghrib' => '17:36' ,
|
58
|
+
'Isha' => '19:06' ,
|
59
|
+
'Midnight' => '00:33' }}
|
60
|
+
it{subject.must_equal expected}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
context 'time format is 24h, times names are custom and settings are default' do
|
67
|
+
context 'when date is 2013/12/16, location is Amman/Jordan and timezone 3' do
|
68
|
+
let(:pt){PrayerTimes.new method_name, times_names: {asr: "Aser", isha: "Ishaa"}}
|
69
|
+
subject{pt.get_times([2013,12,16], [31,36], 3)}
|
70
|
+
let(:expected){{
|
71
|
+
'Imsak' => '05:48',
|
72
|
+
'Fajr' => '05:58',
|
73
|
+
'Sunrise' => '07:27',
|
74
|
+
'Dhuhr' => '12:32',
|
75
|
+
'Aser' => '15:18' ,
|
76
|
+
'Sunset' => '17:36' ,
|
77
|
+
'Maghrib' => '17:36' ,
|
78
|
+
'Ishaa' => '19:06' ,
|
79
|
+
'Midnight' => '00:32' }}
|
80
|
+
it{subject.must_equal expected}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'time format is 12h, suffixes are custom and other settings are default' do
|
85
|
+
context 'when date is 2013/12/16, location is Amman/Jordan and timezone 3' do
|
86
|
+
let(:pt){PrayerTimes.new method_name, time_format: '12h', time_suffixes: {:am => ' صباحا', :pm => ' مساءا'}}
|
87
|
+
subject{pt.get_times([2013,12,16], [31,36], 3)}
|
88
|
+
let(:expected){{
|
89
|
+
'Imsak' => '5:48 صباحا',
|
90
|
+
'Fajr' => '5:58 صباحا',
|
91
|
+
'Sunrise' => '7:27 صباحا',
|
92
|
+
'Dhuhr' => '12:32 مساءا',
|
93
|
+
'Asr' => '3:18 مساءا' ,
|
94
|
+
'Sunset' => '5:36 مساءا' ,
|
95
|
+
'Maghrib' => '5:36 مساءا' ,
|
96
|
+
'Isha' => '7:06 مساءا' ,
|
97
|
+
'Midnight' => '12:32 صباحا' }}
|
98
|
+
it{subject.must_equal expected}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when method is Turkey' do
|
104
|
+
context 'when date is 2013/12/17, location is Fatih/Istanbul/Turkey and timezone +2' do
|
105
|
+
let(:pt){PrayerTimes.new "Turkey", time_format: '12h'}
|
106
|
+
subject{pt.get_times([2013,12,17], [41.02,28.94], 2)}
|
107
|
+
let(:expected){{
|
108
|
+
'Imsak' => '5:34AM',
|
109
|
+
'Fajr' => '5:42AM',
|
110
|
+
'Sunrise' => '7:16AM',
|
111
|
+
'Dhuhr' => '12:06PM',
|
112
|
+
'Asr' => '2:24PM' ,
|
113
|
+
'Sunset' => '4:37PM' ,
|
114
|
+
'Maghrib' => '4:46PM' ,
|
115
|
+
'Isha' => '6:13PM' ,
|
116
|
+
'Midnight' => '12:00AM' }}
|
117
|
+
it{subject.must_equal expected}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe PrayerTimes::Calculator do
|
4
|
+
|
5
|
+
subject{PrayerTimes::Calculator.new "MWL",{}}
|
6
|
+
it{subject.must_respond_to :calculation_method}
|
7
|
+
it{subject.must_respond_to :time_format}
|
8
|
+
it{subject.must_respond_to :times_names}
|
9
|
+
it{subject.must_respond_to :time_suffixes}
|
10
|
+
it{subject.must_respond_to :invalid_time}
|
11
|
+
it{subject.must_respond_to :iterations_count}
|
12
|
+
it{subject.must_respond_to :times_offsets}
|
13
|
+
it{subject.must_respond_to :get_times}
|
14
|
+
it{subject.must_be_kind_of PrayerTimes::Setters}
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe PrayerTimes::MathHelpers do
|
4
|
+
|
5
|
+
subject{ Object.new.extend PrayerTimes::MathHelpers}
|
6
|
+
|
7
|
+
describe "#radians" do
|
8
|
+
it {subject.must_respond_to(:radians)}
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#degrees" do
|
12
|
+
it {subject.must_respond_to(:degrees)}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#rsin" do
|
16
|
+
it {subject.must_respond_to(:rsin)}
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#rcos" do
|
20
|
+
it {subject.must_respond_to(:rcos)}
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#rtan" do
|
24
|
+
it {subject.must_respond_to(:rtan)}
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#darcsin" do
|
28
|
+
it {subject.must_respond_to(:darcsin)}
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#darccos" do
|
32
|
+
it {subject.must_respond_to(:darccos)}
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#darctan" do
|
36
|
+
it {subject.must_respond_to(:darctan)}
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#darccot" do
|
40
|
+
it {subject.must_respond_to(:darccot)}
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#darctan2" do
|
44
|
+
it {subject.must_respond_to(:darctan2)}
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe PrayerTimes do
|
4
|
+
|
5
|
+
describe "Class" do
|
6
|
+
subject{PrayerTimes}
|
7
|
+
it{subject.must_respond_to :calculation_method}
|
8
|
+
it{subject.must_respond_to :calculation_methods}
|
9
|
+
it{subject.must_respond_to :time_format}
|
10
|
+
it{subject.must_respond_to :times_names}
|
11
|
+
it{subject.must_respond_to :time_suffixes}
|
12
|
+
it{subject.must_respond_to :invalid_time}
|
13
|
+
it{subject.must_respond_to :iterations_count}
|
14
|
+
it{subject.must_respond_to :times_offsets}
|
15
|
+
it{subject.must_be_kind_of PrayerTimes::Setters}
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".new" do
|
19
|
+
subject{PrayerTimes.new}
|
20
|
+
it{subject.must_be_kind_of PrayerTimes::Calculator}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe PrayerTimes::Setters do
|
4
|
+
|
5
|
+
subject{PrayerTimes::Calculator.new "MWL",{}}
|
6
|
+
describe "#iteration_count=" do
|
7
|
+
context "when number not number or out of range" do
|
8
|
+
["",1,6].each do |num|
|
9
|
+
let(:iterations_count){8}
|
10
|
+
let(:result){subject.iterations_count = iterations_count; subject.iterations_count}
|
11
|
+
it{result.must_equal PrayerTimes.iterations_count}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when in range" do
|
16
|
+
let(:iterations_count){3}
|
17
|
+
let(:result){subject.iterations_count = iterations_count; subject.iterations_count}
|
18
|
+
it{result.must_equal iterations_count}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#time_format=" do
|
23
|
+
context "when wrong value" do
|
24
|
+
let(:time_format){"kh"}
|
25
|
+
let(:result){subject.time_format = time_format; subject.time_format}
|
26
|
+
it{result.must_equal PrayerTimes.time_format}
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when right value" do
|
30
|
+
let(:time_format){'12h'}
|
31
|
+
let(:result){subject.time_format = time_format; subject.time_format}
|
32
|
+
it{result.must_equal time_format}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#invalid_time=" do
|
37
|
+
context "when nil" do
|
38
|
+
let(:invalid_time){nil}
|
39
|
+
let(:result){subject.invalid_time = invalid_time; subject.invalid_time}
|
40
|
+
it{result.must_equal PrayerTimes.invalid_time}
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when other value" do
|
44
|
+
let(:invalid_time){'*****'}
|
45
|
+
let(:result){subject.invalid_time = invalid_time; subject.invalid_time}
|
46
|
+
it{result.must_equal invalid_time}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#time_suffixes=" do
|
51
|
+
context "when wrong value" do
|
52
|
+
let(:time_suffixes){{:amz => "صباحا", :pm => "مساءا"}}
|
53
|
+
let(:result){subject.time_suffixes = time_suffixes; subject.time_suffixes}
|
54
|
+
it{result.must_equal PrayerTimes.time_suffixes.merge({:pm => "مساءا"})}
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when right value" do
|
58
|
+
let(:time_suffixes){{:am => "صباحا", :pm => "مساءا"}}
|
59
|
+
let(:result){subject.time_suffixes = time_suffixes; subject.time_suffixes}
|
60
|
+
it{result.must_equal PrayerTimes.time_suffixes.merge(time_suffixes)}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#times_names=" do
|
65
|
+
context "when wrong value" do
|
66
|
+
let(:times_names){{:aser => "Aser", :koko => "Dano", :isha => "Ishaa"}}
|
67
|
+
let(:result){subject.times_names = times_names; subject.times_names}
|
68
|
+
it{result.must_equal PrayerTimes.times_names.merge({:isha => "Ishaa"})}
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when right value" do
|
72
|
+
let(:times_names){{:asr => "Aser", :isha => "Ishaa"}}
|
73
|
+
let(:result){subject.times_names = times_names; subject.times_names}
|
74
|
+
it{result.must_equal PrayerTimes.times_names.merge(times_names)}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#times_offsets=" do
|
79
|
+
context "when wrong value" do
|
80
|
+
let(:times_offsets){{:aser => 10, :dhuhr => "Dano", :isha => 3.6}}
|
81
|
+
let(:result){subject.times_offsets = times_offsets; subject.times_offsets}
|
82
|
+
it{result.must_equal PrayerTimes.times_offsets.merge({:isha => 3.6})}
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when right value" do
|
86
|
+
let(:times_offsets){{:asr => 1, :dhuhr => 1.2, :isha => 3.6}}
|
87
|
+
let(:result){subject.times_offsets = times_offsets; subject.times_offsets}
|
88
|
+
it{result.must_equal PrayerTimes.times_offsets.merge(times_offsets)}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#calculation_method=" do
|
93
|
+
context "when wrong value" do
|
94
|
+
let(:calculation_method){'K@mp'}
|
95
|
+
let(:result){subject.calculation_method = calculation_method; subject.calculation_method}
|
96
|
+
it{result.must_equal PrayerTimes.calculation_method}
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when right value" do
|
100
|
+
let(:calculation_method){'Makkah'}
|
101
|
+
let(:result){subject.calculation_method = calculation_method; subject.calculation_method}
|
102
|
+
it{result.must_equal PrayerTimes.calculation_methods['Makkah']}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|