bahai_date 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ module BahaiDate
2
+ VERSION = "1.1.0"
3
+ end
@@ -1,13 +1,12 @@
1
1
  module BahaiDate
2
-
3
2
  class Weekday
4
- TITLES = %w[Jalal Jamal Kamal Fidal Idal Istijlal Istiqlal]
5
- TITLES_HTML = %w[Jalál Jamál Kamál Fiḍál ‘Idál Istijlál Istiqlál]
6
- TITLES_EN = %w[Glory Beauty Perfection Grace Justice Majesty Independence]
7
- ENGLISH_EQUIVALENTS = %w[Saturday Sunday Monday Tuesday Wednesday Thursday Friday]
3
+ TITLES = %w(Jalal Jamal Kamal Fidal Idal Istijlal Istiqlal)
4
+ TITLES_HTML = %w(Jalál Jamál Kamál Fiḍál ‘Idál Istijlál Istiqlál)
5
+ TITLES_EN = %w(Glory Beauty Perfection Grace Justice Majesty Independence)
6
+ ENGLISH_EQUIVALENTS = %w(Saturday Sunday Monday Tuesday Wednesday Thursday Friday)
8
7
 
9
8
  attr_reader :number
10
-
9
+
11
10
  def initialize(number_arg)
12
11
  validate number_arg
13
12
  @number = number_arg.to_i
@@ -33,7 +32,7 @@ module BahaiDate
33
32
  ENGLISH_EQUIVALENTS[title_index]
34
33
  end
35
34
 
36
- private
35
+ private
37
36
 
38
37
  def title_index
39
38
  @number - 1
@@ -41,11 +40,9 @@ module BahaiDate
41
40
 
42
41
  def validate(number_arg)
43
42
  number = number_arg.to_i
44
- if (number < 1 || number > 7)
45
- raise ArgumentError, "'#{number}' is not a valid weekday. Please use 1 to 7."
46
- end
47
- end
43
+ return if (1..7).include? number
48
44
 
45
+ fail ArgumentError, "'#{number}' is not a valid weekday. Please use 1 to 7."
46
+ end
49
47
  end
50
-
51
48
  end
@@ -1,12 +1,9 @@
1
- require_relative 'month'
2
-
3
1
  module BahaiDate
2
+ class Year
3
+ TITLES = %w(Alif Ba Ab Dal Bab Vav Abad Jad Baha Hubb Bahhaj Javab Ahad Vahhab Vidad Badi Bahi Abha Vahid)
4
+ TITLES_HTML = %w(Alif Bá’ Ab Dál Báb Váv Abad Jád Bahá Ḥubb Bahháj Javáb Aḥad Vahháb Vidád Badí‘ Bahí Abhá Váḥid)
5
+ TITLES_EN = %w(A B Father D Gate V Eternity Generosity Splendour Love Delightful Answer Single Bountiful Affection Beginning Luminous Most Luminous Unity)
4
6
 
5
- class Year
6
- TITLES = %w[Alif Ba Ab Dal Bab Vav Abad Jad Baha Hubb Bahhaj Javab Ahad Vahhab Vidad Badi Bahi Abha Vahid]
7
- TITLES_HTML = %w[Alif Bá’ Ab Dál Báb Váv Abad Jád Bahá Ḥubb Bahháj Javáb Aḥad Vahháb Vidád Badí‘ Bahí Abhá Váḥid]
8
- TITLES_EN = %w[A B Father D Gate V Eternity Generosity Splendour Love Delightful Answer Single Bountiful Affection Beginning Luminous Most Luminous Unity]
9
-
10
7
  attr_reader :bahai_era, :number, :vahid, :kull_i_shay, :months
11
8
 
12
9
  def initialize(number_arg)
@@ -17,7 +14,7 @@ module BahaiDate
17
14
  end
18
15
 
19
16
  def to_s
20
- @bahai_era.to_s
17
+ @bahai_era.to_s
21
18
  end
22
19
 
23
20
  def title
@@ -32,7 +29,7 @@ module BahaiDate
32
29
  TITLES_HTML[title_index]
33
30
  end
34
31
 
35
- def set_month(month_number)
32
+ def add_month(month_number)
36
33
  if @months[month_number]
37
34
  @months[month_number]
38
35
  else
@@ -40,7 +37,7 @@ module BahaiDate
40
37
  end
41
38
  end
42
39
 
43
- private
40
+ private
44
41
 
45
42
  def title_index
46
43
  @number - 1
@@ -48,9 +45,9 @@ module BahaiDate
48
45
 
49
46
  def validate(number_arg)
50
47
  number = number_arg.to_i
51
- if (number < 1)
52
- raise ArgumentError, "'#{number}' is not a valid year. Please use a number greater than or equal to 1."
53
- end
48
+ return unless number < 1
49
+
50
+ fail ArgumentError, "'#{number}' is not a valid year. Please use a number greater than or equal to 1."
54
51
  end
55
52
 
56
53
  def calculate_number_vahid_and_kull_i_shay
@@ -60,7 +57,5 @@ module BahaiDate
60
57
  @vahid += 1
61
58
  @kull_i_shay += 1
62
59
  end
63
-
64
60
  end
65
-
66
61
  end
@@ -1,32 +1,25 @@
1
- require_relative 'year'
2
- require_relative 'bahai_date'
3
-
4
1
  module BahaiDate
5
-
6
2
  class YearCalendar < Year
7
-
8
3
  def initialize(number_arg)
9
4
  super
10
5
  populate_calendar
11
6
  end
12
7
 
13
- private
8
+ private
14
9
 
15
10
  def populate_calendar
16
11
  date = BahaiDate.new(year: @bahai_era, month: 1, day: 1)
17
- while date.year.bahai_era == @bahai_era do
12
+ while date.year.bahai_era == @bahai_era
18
13
  add_to_calendar date
19
14
  date.next_day!
20
15
  end
21
16
  end
22
-
17
+
23
18
  def add_to_calendar(date)
24
- month = set_month date.month.number
25
- day = month.set_day date.day.number
26
- day.set_weekday date.weekday
27
- day.set_occasions date.occasions
19
+ month = add_month date.month.number
20
+ day = month.add_day date.day.number
21
+ day.weekday = date.weekday
22
+ day.occasions = date.occasions
28
23
  end
29
-
30
24
  end
31
-
32
25
  end
@@ -1,23 +1,17 @@
1
- require 'date'
2
-
3
1
  module BahaiDate
4
-
5
2
  class YearData
6
-
7
3
  # valid up to 2148
8
4
  LEAP_YEARS = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152, 156, 160, 164, 168, 174, 178, 182, 187, 191, 195, 199, 203, 207, 211, 216, 220, 224, 228, 232, 236, 240, 244, 249, 253, 257, 261, 265, 269, 273, 277, 282, 286, 290, 294, 298, 302]
9
5
  # valid up to 2149
10
- NAWRUZ_DAYS = {2015=>21, 2016=>20, 2017=>20, 2018=>21, 2019=>21, 2020=>20, 2021=>20, 2022=>21, 2023=>21, 2024=>20, 2025=>20, 2026=>21, 2027=>21, 2028=>20, 2029=>20, 2030=>20, 2031=>21, 2032=>20, 2033=>20, 2034=>20, 2035=>21, 2036=>20, 2037=>20, 2038=>20, 2039=>21, 2040=>20, 2041=>20, 2042=>20, 2043=>21, 2044=>20, 2045=>20, 2046=>20, 2047=>21, 2048=>20, 2049=>20, 2050=>20, 2051=>21, 2052=>20, 2053=>20, 2054=>20, 2055=>21, 2056=>20, 2057=>20, 2058=>20, 2059=>20, 2060=>20, 2061=>20, 2062=>20, 2063=>20, 2064=>20, 2065=>20, 2066=>20, 2067=>20, 2068=>20, 2069=>20, 2070=>20, 2071=>20, 2072=>20, 2073=>20, 2074=>20, 2075=>20, 2076=>20, 2077=>20, 2078=>20, 2079=>20, 2080=>20, 2081=>20, 2082=>20, 2083=>20, 2084=>20, 2085=>20, 2086=>20, 2087=>20, 2088=>20, 2089=>20, 2090=>20, 2091=>20, 2092=>19, 2093=>20, 2094=>20, 2095=>20, 2096=>19, 2097=>20, 2098=>20, 2099=>20, 2100=>20, 2101=>21, 2102=>21, 2103=>21, 2104=>20, 2105=>21, 2106=>21, 2107=>21, 2108=>20, 2109=>21, 2110=>21, 2111=>21, 2112=>20, 2113=>21, 2114=>21, 2115=>21, 2116=>20, 2117=>21, 2118=>21, 2119=>21, 2120=>20, 2121=>21, 2122=>21, 2123=>21, 2124=>20, 2125=>20, 2126=>21, 2127=>21, 2128=>20, 2129=>20, 2130=>21, 2131=>21, 2132=>20, 2133=>20, 2134=>21, 2135=>21, 2136=>20, 2137=>20, 2138=>21, 2139=>21, 2140=>20, 2141=>20, 2142=>21, 2143=>21, 2144=>20, 2145=>20, 2146=>21, 2147=>21, 2148=>20, 2149=>20}
6
+ NAWRUZ_DAYS = { 2015 => 21, 2016 => 20, 2017 => 20, 2018 => 21, 2019 => 21, 2020 => 20, 2021 => 20, 2022 => 21, 2023 => 21, 2024 => 20, 2025 => 20, 2026 => 21, 2027 => 21, 2028 => 20, 2029 => 20, 2030 => 20, 2031 => 21, 2032 => 20, 2033 => 20, 2034 => 20, 2035 => 21, 2036 => 20, 2037 => 20, 2038 => 20, 2039 => 21, 2040 => 20, 2041 => 20, 2042 => 20, 2043 => 21, 2044 => 20, 2045 => 20, 2046 => 20, 2047 => 21, 2048 => 20, 2049 => 20, 2050 => 20, 2051 => 21, 2052 => 20, 2053 => 20, 2054 => 20, 2055 => 21, 2056 => 20, 2057 => 20, 2058 => 20, 2059 => 20, 2060 => 20, 2061 => 20, 2062 => 20, 2063 => 20, 2064 => 20, 2065 => 20, 2066 => 20, 2067 => 20, 2068 => 20, 2069 => 20, 2070 => 20, 2071 => 20, 2072 => 20, 2073 => 20, 2074 => 20, 2075 => 20, 2076 => 20, 2077 => 20, 2078 => 20, 2079 => 20, 2080 => 20, 2081 => 20, 2082 => 20, 2083 => 20, 2084 => 20, 2085 => 20, 2086 => 20, 2087 => 20, 2088 => 20, 2089 => 20, 2090 => 20, 2091 => 20, 2092 => 19, 2093 => 20, 2094 => 20, 2095 => 20, 2096 => 19, 2097 => 20, 2098 => 20, 2099 => 20, 2100 => 20, 2101 => 21, 2102 => 21, 2103 => 21, 2104 => 20, 2105 => 21, 2106 => 21, 2107 => 21, 2108 => 20, 2109 => 21, 2110 => 21, 2111 => 21, 2112 => 20, 2113 => 21, 2114 => 21, 2115 => 21, 2116 => 20, 2117 => 21, 2118 => 21, 2119 => 21, 2120 => 20, 2121 => 21, 2122 => 21, 2123 => 21, 2124 => 20, 2125 => 20, 2126 => 21, 2127 => 21, 2128 => 20, 2129 => 20, 2130 => 21, 2131 => 21, 2132 => 20, 2133 => 20, 2134 => 21, 2135 => 21, 2136 => 20, 2137 => 20, 2138 => 21, 2139 => 21, 2140 => 20, 2141 => 20, 2142 => 21, 2143 => 21, 2144 => 20, 2145 => 20, 2146 => 21, 2147 => 21, 2148 => 20, 2149 => 20 }
11
7
 
12
8
  def self.nawruz_for(year)
13
9
  nawruz_day = year < 2015 ? 21 : NAWRUZ_DAYS[year]
14
10
  Date.new(year, 3, nawruz_day)
15
11
  end
16
12
 
17
- def self.is_leap?(year)
13
+ def self.leap?(year)
18
14
  LEAP_YEARS.include? year
19
15
  end
20
-
21
16
  end
22
-
23
17
  end
@@ -1,22 +1,19 @@
1
- require 'bahai_date/bahai_date'
2
-
3
1
  module BahaiDate
4
-
5
2
  describe BahaiDate do
6
3
 
7
- it "can be created from a year, month and day" do
4
+ it 'can be created from a year, month and day' do
8
5
  bahai_date = BahaiDate.new(year: 1, month: 1, day: 1)
9
6
 
10
7
  expect(bahai_date).to_not be_nil
11
8
  end
12
9
 
13
- it "can be created from a gregorian Date object" do
10
+ it 'can be created from a gregorian Date object' do
14
11
  bahai_date = BahaiDate.new(date: Date.new(2010, 1, 1))
15
12
 
16
13
  expect(bahai_date).to_not be_nil
17
14
  end
18
15
 
19
- it "raises an error if invalid arguments are passed to the initializer" do
16
+ it 'raises an error if invalid arguments are passed to the initializer' do
20
17
  expect { BahaiDate.new }.to raise_error(ArgumentError)
21
18
  expect { BahaiDate.new({}) }.to raise_error(ArgumentError)
22
19
  expect { BahaiDate.new(day: 1) }.to raise_error(ArgumentError)
@@ -24,228 +21,235 @@ module BahaiDate
24
21
 
25
22
  context "when validating the Baha'i Era date" do
26
23
 
27
- context "year" do
28
- it "raises an error if less than 1" do
29
- expect { BahaiDate.new(year: 0, month: 1, day: 1)
30
- }.to raise_error(ArgumentError)
24
+ context 'year' do
25
+ it 'raises an error if less than 1' do
26
+ expect do
27
+ BahaiDate.new(year: 0, month: 1, day: 1)
28
+ end.to raise_error(ArgumentError)
31
29
  end
32
30
  end
33
31
 
34
- context "month" do
35
- it "raises an error if 0" do
36
- expect { BahaiDate.new(year: 1, month: 0, day: 1)
37
- }.to raise_error(ArgumentError)
32
+ context 'month' do
33
+ it 'raises an error if 0' do
34
+ expect do
35
+ BahaiDate.new(year: 1, month: 0, day: 1)
36
+ end.to raise_error(ArgumentError)
38
37
  end
39
- it "raises an error if less than -1" do
40
- expect { BahaiDate.new(year: 1, month: -2, day: 1)
41
- }.to raise_error(ArgumentError)
38
+ it 'raises an error if less than -1' do
39
+ expect do
40
+ BahaiDate.new(year: 1, month: -2, day: 1)
41
+ end.to raise_error(ArgumentError)
42
42
  end
43
- it "raises an error if greater than 19" do
44
- expect { BahaiDate.new(year: 1, month: 20, day: 1)
45
- }.to raise_error(ArgumentError)
43
+ it 'raises an error if greater than 19' do
44
+ expect do
45
+ BahaiDate.new(year: 1, month: 20, day: 1)
46
+ end.to raise_error(ArgumentError)
46
47
  end
47
48
  end
48
49
 
49
- context "day" do
50
- it "raises an error if less than 1" do
51
- expect { BahaiDate.new(year: 1, month: 1, day: 0)
52
- }.to raise_error(ArgumentError)
53
- end
54
- it "raises an error if greater than 19" do
55
- expect { BahaiDate.new(year: 1, month: 1, day: 20)
56
- }.to raise_error(ArgumentError)
57
- end
58
- context "in Ayyam-i-Ha" do
59
- it "raises an error if greater than 4 on a non-leap year" do
60
- expect { BahaiDate.new(year: 1, month: -1, day: 5)
61
- }.to raise_error(ArgumentError)
50
+ context 'day' do
51
+ it 'raises an error if less than 1' do
52
+ expect do
53
+ BahaiDate.new(year: 1, month: 1, day: 0)
54
+ end.to raise_error(ArgumentError)
55
+ end
56
+ it 'raises an error if greater than 19' do
57
+ expect do
58
+ BahaiDate.new(year: 1, month: 1, day: 20)
59
+ end.to raise_error(ArgumentError)
60
+ end
61
+ context 'in Ayyam-i-Ha' do
62
+ it 'raises an error if greater than 4 on a non-leap year' do
63
+ expect do
64
+ BahaiDate.new(year: 1, month: -1, day: 5)
65
+ end.to raise_error(ArgumentError)
62
66
  end
63
67
  it "doesn't raise an error if 5 on a leap year" do
64
- expect { BahaiDate.new(year: 4, month: -1, day: 5)
65
- }.not_to raise_error
68
+ expect do
69
+ BahaiDate.new(year: 4, month: -1, day: 5)
70
+ end.not_to raise_error
66
71
  end
67
- it "raises an error if greater than 5 on a leap year" do
68
- expect { BahaiDate.new(year: 4, month: -1, day: 6)
69
- }.to raise_error(ArgumentError)
72
+ it 'raises an error if greater than 5 on a leap year' do
73
+ expect do
74
+ BahaiDate.new(year: 4, month: -1, day: 6)
75
+ end.to raise_error(ArgumentError)
70
76
  end
71
77
  end
72
78
  end
73
79
 
74
80
  end
75
81
 
76
- it "exposes weekday, day, month, year and gregorian_date" do
82
+ it 'exposes weekday, day, month, year and gregorian_date' do
77
83
  bahai_date = BahaiDate.new(year: 1, month: 1, day: 1)
78
84
 
79
- expect(bahai_date.weekday).to be_an_instance_of(Weekday)
80
- expect(bahai_date.day).to be_an_instance_of(Day)
81
- expect(bahai_date.month).to be_an_instance_of(Month)
82
- expect(bahai_date.year).to be_an_instance_of(Year)
85
+ expect(bahai_date.weekday).to be_an_instance_of(Weekday)
86
+ expect(bahai_date.day).to be_an_instance_of(Day)
87
+ expect(bahai_date.month).to be_an_instance_of(Month)
88
+ expect(bahai_date.year).to be_an_instance_of(Year)
83
89
  expect(bahai_date.gregorian_date).to be_an_instance_of(Date)
84
90
  end
85
91
 
86
- context "when converting to a gregorian date" do
92
+ context 'when converting to a gregorian date' do
87
93
 
88
- it "handles the first day of the calendar" do
94
+ it 'handles the first day of the calendar' do
89
95
  bahai_date = BahaiDate.new(year: 1, month: 1, day: 1)
90
- expect(bahai_date.gregorian_date).to eq(Date.new(1844,3,21))
96
+ expect(bahai_date.gregorian_date).to eq(Date.new(1844, 3, 21))
91
97
  end
92
98
 
93
- it "handles the last day of the year" do
99
+ it 'handles the last day of the year' do
94
100
  bahai_date = BahaiDate.new(year: 1, month: 19, day: 19)
95
- expect(bahai_date.gregorian_date).to eq(Date.new(1845,3,20))
101
+ expect(bahai_date.gregorian_date).to eq(Date.new(1845, 3, 20))
96
102
  end
97
103
 
98
- it "handles the year component" do
104
+ it 'handles the year component' do
99
105
  bahai_date = BahaiDate.new(year: 2, month: 1, day: 1)
100
- expect(bahai_date.gregorian_date).to eq(Date.new(1845,3,21))
106
+ expect(bahai_date.gregorian_date).to eq(Date.new(1845, 3, 21))
101
107
  end
102
108
 
103
- context "in a leap year" do
104
- it "handles the day before Ayyam-i-Ha" do
109
+ context 'in a leap year' do
110
+ it 'handles the day before Ayyam-i-Ha' do
105
111
  bahai_date = BahaiDate.new(year: 168, month: 18, day: 19)
106
- expect(bahai_date.gregorian_date).to eq(Date.new(2012,2,25))
112
+ expect(bahai_date.gregorian_date).to eq(Date.new(2012, 2, 25))
107
113
  end
108
114
 
109
- it "handles the first day of Ayyam-i-Ha" do
115
+ it 'handles the first day of Ayyam-i-Ha' do
110
116
  bahai_date = BahaiDate.new(year: 168, month: -1, day: 1)
111
- expect(bahai_date.gregorian_date).to eq(Date.new(2012,2,26))
117
+ expect(bahai_date.gregorian_date).to eq(Date.new(2012, 2, 26))
112
118
  end
113
119
 
114
- it "handles the last day of Ayyam-i-Ha" do
120
+ it 'handles the last day of Ayyam-i-Ha' do
115
121
  bahai_date = BahaiDate.new(year: 168, month: -1, day: 5)
116
- expect(bahai_date.gregorian_date).to eq(Date.new(2012,3,1))
122
+ expect(bahai_date.gregorian_date).to eq(Date.new(2012, 3, 1))
117
123
  end
118
124
 
119
- it "handles the first day of the month after Ayyam-i-Ha" do
125
+ it 'handles the first day of the month after Ayyam-i-Ha' do
120
126
  bahai_date = BahaiDate.new(year: 168, month: 19, day: 1)
121
- expect(bahai_date.gregorian_date).to eq(Date.new(2012,3,2))
127
+ expect(bahai_date.gregorian_date).to eq(Date.new(2012, 3, 2))
122
128
  end
123
129
  end
124
130
 
125
- context "in a non-leap year" do
126
- it "handles the last day of Ayyam-i-Ha" do
131
+ context 'in a non-leap year' do
132
+ it 'handles the last day of Ayyam-i-Ha' do
127
133
  bahai_date = BahaiDate.new(year: 169, month: -1, day: 4)
128
- expect(bahai_date.gregorian_date).to eq(Date.new(2013,3,1))
134
+ expect(bahai_date.gregorian_date).to eq(Date.new(2013, 3, 1))
129
135
  end
130
136
  end
131
137
 
132
138
  end
133
139
 
140
+ context 'when converting from gregorian date' do
134
141
 
135
- context "when converting from gregorian date" do
136
-
137
- it "handles the first day of the calendar" do
138
- bahai_date = BahaiDate.new(date: Date.new(1844,3,21))
139
- expect(bahai_date.year.bahai_era).to be 1
140
- expect(bahai_date.month.number).to be 1
141
- expect(bahai_date.day.number).to be 1
142
+ it 'handles the first day of the calendar' do
143
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 21))
144
+ expect(bahai_date.year.bahai_era).to be 1
145
+ expect(bahai_date.month.number).to be 1
146
+ expect(bahai_date.day.number).to be 1
142
147
  end
143
148
 
144
- it "handles the last day of the year" do
145
- bahai_date = BahaiDate.new(date: Date.new(1845,3,20))
149
+ it 'handles the last day of the year' do
150
+ bahai_date = BahaiDate.new(date: Date.new(1845, 3, 20))
146
151
  expect(bahai_date.year.bahai_era).to be 1
147
152
  expect(bahai_date.month.number).to be 19
148
153
  expect(bahai_date.day.number).to be 19
149
154
  end
150
155
 
151
- it "handles the year component" do
152
- bahai_date = BahaiDate.new(date: Date.new(1845,3,21))
156
+ it 'handles the year component' do
157
+ bahai_date = BahaiDate.new(date: Date.new(1845, 3, 21))
153
158
  expect(bahai_date.year.bahai_era).to be 2
154
159
  expect(bahai_date.month.number).to be 1
155
160
  expect(bahai_date.day.number).to be 1
156
161
  end
157
162
 
158
- context "in a leap year" do
159
- it "handles the day before Ayyam-i-Ha" do
160
- bahai_date = BahaiDate.new(date: Date.new(2012,2,25))
163
+ context 'in a leap year' do
164
+ it 'handles the day before Ayyam-i-Ha' do
165
+ bahai_date = BahaiDate.new(date: Date.new(2012, 2, 25))
161
166
  expect(bahai_date.year.bahai_era).to be 168
162
167
  expect(bahai_date.month.number).to be 18
163
168
  expect(bahai_date.day.number).to be 19
164
169
  end
165
170
 
166
- it "handles the first day of Ayyam-i-Ha" do
167
- bahai_date = BahaiDate.new(date: Date.new(2012,2,26))
171
+ it 'handles the first day of Ayyam-i-Ha' do
172
+ bahai_date = BahaiDate.new(date: Date.new(2012, 2, 26))
168
173
  expect(bahai_date.year.bahai_era).to be 168
169
- expect(bahai_date.month.number).to be -1
174
+ expect(bahai_date.month.number).to be(-1)
170
175
  expect(bahai_date.day.number).to be 1
171
176
  end
172
177
 
173
- it "handles the last day of Ayyam-i-Ha" do
174
- bahai_date = BahaiDate.new(date: Date.new(2012,3,1))
178
+ it 'handles the last day of Ayyam-i-Ha' do
179
+ bahai_date = BahaiDate.new(date: Date.new(2012, 3, 1))
175
180
  expect(bahai_date.year.bahai_era).to be 168
176
- expect(bahai_date.month.number).to be -1
181
+ expect(bahai_date.month.number).to be(-1)
177
182
  expect(bahai_date.day.number).to be 5
178
183
  end
179
184
 
180
- it "handles the first day of the month after Ayyam-i-Ha" do
181
- bahai_date = BahaiDate.new(date: Date.new(2012,3,2))
185
+ it 'handles the first day of the month after Ayyam-i-Ha' do
186
+ bahai_date = BahaiDate.new(date: Date.new(2012, 3, 2))
182
187
  expect(bahai_date.year.bahai_era).to be 168
183
188
  expect(bahai_date.month.number).to be 19
184
189
  expect(bahai_date.day.number).to be 1
185
190
  end
186
191
  end
187
192
 
188
- context "in a non-leap year" do
189
- it "handles the last day of Ayyam-i-Ha" do
190
- bahai_date = BahaiDate.new(date: Date.new(2013,3,1))
193
+ context 'in a non-leap year' do
194
+ it 'handles the last day of Ayyam-i-Ha' do
195
+ bahai_date = BahaiDate.new(date: Date.new(2013, 3, 1))
191
196
  expect(bahai_date.year.bahai_era).to be 169
192
- expect(bahai_date.month.number).to be -1
197
+ expect(bahai_date.month.number).to be(-1)
193
198
  expect(bahai_date.day.number).to be 4
194
199
  end
195
200
  end
196
201
 
197
202
  end
198
203
 
199
- it "can get weekday from a gregorian date accurately" do
200
- bahai_date = BahaiDate.new(date: Date.new(1844,3,21))
204
+ it 'can get weekday from a gregorian date accurately' do
205
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 21))
201
206
  expect(bahai_date.weekday.number).to be 6
202
207
 
203
- bahai_date = BahaiDate.new(date: Date.new(1844,3,22))
208
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 22))
204
209
  expect(bahai_date.weekday.number).to be 7
205
210
 
206
- bahai_date = BahaiDate.new(date: Date.new(1844,3,23))
211
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 23))
207
212
  expect(bahai_date.weekday.number).to be 1
208
213
 
209
- bahai_date = BahaiDate.new(date: Date.new(1844,3,24))
214
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 24))
210
215
  expect(bahai_date.weekday.number).to be 2
211
216
 
212
- bahai_date = BahaiDate.new(date: Date.new(1844,3,25))
217
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 25))
213
218
  expect(bahai_date.weekday.number).to be 3
214
219
 
215
- bahai_date = BahaiDate.new(date: Date.new(1844,3,26))
220
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 26))
216
221
  expect(bahai_date.weekday.number).to be 4
217
222
 
218
- bahai_date = BahaiDate.new(date: Date.new(1844,3,27))
223
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 27))
219
224
  expect(bahai_date.weekday.number).to be 5
220
225
 
221
- bahai_date = BahaiDate.new(date: Date.new(1844,3,28))
226
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 28))
222
227
  expect(bahai_date.weekday.number).to be 6
223
228
  end
224
229
 
225
- it "can be converted to string" do
226
- bahai_date = BahaiDate.new(date: Date.new(1844,3,21))
227
- expect(bahai_date.to_s).to eq "1.1.1"
230
+ it 'can be converted to string' do
231
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 21))
232
+ expect(bahai_date.to_s).to eq '1.1.1'
228
233
  end
229
234
 
230
- it "can provide the date in long format" do
231
- bahai_date = BahaiDate.new(date: Date.new(1844,3,21))
232
- expect(bahai_date.long_format).to eq "Istijlal 1 Baha 1 B.E."
235
+ it 'can provide the date in long format' do
236
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 21))
237
+ expect(bahai_date.long_format).to eq 'Istijlal 1 Baha 1 B.E.'
233
238
  end
234
239
 
235
- it "can provide an array of occasions for a given day" do
236
- bahai_date = BahaiDate.new(date: Date.new(1844,3,21))
240
+ it 'can provide an array of occasions for a given day' do
241
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 21))
237
242
  occasions_array = bahai_date.occasions
238
243
  expect(occasions_array.size).to be 2
239
- expect(occasions_array.first.short_title).to eq "Naw-Ruz"
240
- expect(occasions_array.last.short_title).to eq "Feast of Baha"
244
+ expect(occasions_array.first.short_title).to eq 'Naw-Ruz'
245
+ expect(occasions_array.last.short_title).to eq 'Feast of Baha'
241
246
  end
242
247
 
243
- it "can advance to the next day" do
244
- bahai_date = BahaiDate.new(date: Date.new(1844,3,21))
248
+ it 'can advance to the next day' do
249
+ bahai_date = BahaiDate.new(date: Date.new(1844, 3, 21))
245
250
  bahai_date.next_day!
246
- expect(bahai_date.gregorian_date).to eq Date.new(1844,3,22)
251
+ expect(bahai_date.gregorian_date).to eq Date.new(1844, 3, 22)
247
252
  end
248
253
 
249
254
  end
250
-
251
255
  end