sheha 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/sheha/yearly_event.rb +6 -2
- data/sheha.gemspec +1 -1
- data/test/test_sheha.rb +78 -0
- data/test/test_sheha_event.rb +12 -0
- data/test/test_sheha_yearly_event.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f8efa356e26cbe048b15127691da8c5965f9246
|
4
|
+
data.tar.gz: 3de5c01d1bf9e7fe9b3db70cb10e39b195527708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd33e658905c18879aa69d32d3fc0a5298d3269b95fdfa58c767fb01986c0c80c11455104126cedf8b22bb13cf743c5ce6a6a4b8ecf7c9a8fa8d0ba9cd9c83d8
|
7
|
+
data.tar.gz: 9a3c538e35b7d7cb4cbe378dd6c2de7660c0de1302cfbbdaf79e3d80347c4539752465773d101f548156835a32fddaaf5c97b85b2bc570d572c7e2c9425d679d
|
data/README.md
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
Sheha
|
2
2
|
=====
|
3
3
|
|
4
|
-
A Simple Holidays & Events Handler
|
4
|
+
A Simple Holidays & Events Handler
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Sheha is a simple a minimal holidays & events handler. It can identify if a Date is a holiday based on simple rules provided by configuration.
|
10
|
+
You may provide just the dates you need to hold (like non-working days, for saying) or specify a name and description for the event.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
As usual, you can install it using rubygems.
|
15
|
+
|
16
|
+
```
|
17
|
+
$ gem install mote
|
18
|
+
```
|
data/lib/sheha/yearly_event.rb
CHANGED
@@ -2,7 +2,7 @@ class Sheha::YearlyEvent < Sheha::Event
|
|
2
2
|
def initialize(month, month_day)
|
3
3
|
Sheha::Helper.validate_month(month)
|
4
4
|
Sheha::Helper.validate_month_day(month_day)
|
5
|
-
super "#{month}#{month_day}".to_i
|
5
|
+
super "#{month}#{two_digits_day(month_day)}".to_i
|
6
6
|
end
|
7
7
|
|
8
8
|
def month
|
@@ -20,7 +20,7 @@ class Sheha::YearlyEvent < Sheha::Event
|
|
20
20
|
|
21
21
|
def month_day=(month_day)
|
22
22
|
Sheha::Helper.validate_month_day(month_day)
|
23
|
-
@id = "#{four_digits_id[0..1]}#{month_day}".to_i
|
23
|
+
@id = "#{four_digits_id[0..1]}#{two_digits_day(month_day)}".to_i
|
24
24
|
end
|
25
25
|
|
26
26
|
def event?(date)
|
@@ -32,6 +32,10 @@ class Sheha::YearlyEvent < Sheha::Event
|
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
|
+
def two_digits_day(day)
|
36
|
+
"%02d" % day
|
37
|
+
end
|
38
|
+
|
35
39
|
def four_digits_id
|
36
40
|
"%04d" % @id
|
37
41
|
end
|
data/sheha.gemspec
CHANGED
data/test/test_sheha.rb
CHANGED
@@ -3,6 +3,84 @@ require 'sheha'
|
|
3
3
|
|
4
4
|
class ShehaTest < Test::Unit::TestCase
|
5
5
|
|
6
|
+
# def test_sheha_describe
|
7
|
+
# sheha = Sheha.new
|
8
|
+
# sheha.describe do
|
9
|
+
# weekly do
|
10
|
+
# on "wednesday" do
|
11
|
+
# name "Some Name"
|
12
|
+
# description "Some description"
|
13
|
+
# end
|
14
|
+
|
15
|
+
# from_to "saturday", "sunday" do
|
16
|
+
# name "Some Other Name"
|
17
|
+
# description "Some other description"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# monthly do
|
22
|
+
# on 1 do
|
23
|
+
# name "Some Name"
|
24
|
+
# description "Some description"
|
25
|
+
# end
|
26
|
+
|
27
|
+
# from_to 25, 31 do
|
28
|
+
# name "Some Other Name"
|
29
|
+
# description "Some other description"
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
# yearly do
|
34
|
+
# from_to [1, 1], [1, 7] do
|
35
|
+
# name "Some Name"
|
36
|
+
# description "Some description"
|
37
|
+
# end
|
38
|
+
|
39
|
+
# on 12, 25 do
|
40
|
+
# name "Some Other Name"
|
41
|
+
# description "Some other description"
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
|
45
|
+
# one_time do
|
46
|
+
# on Date.new(2013, 11, 20) do
|
47
|
+
# name "Some Name"
|
48
|
+
# description "Some description"
|
49
|
+
# end
|
50
|
+
|
51
|
+
# from_to Date.new(2013, 12, 1), Date.new(2013, 12, 5) do
|
52
|
+
# name "Some Other Name"
|
53
|
+
# description "Some other description"
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
|
58
|
+
# assert sheha.event? Date.new(2012, 12, 25) # Validating against a know configured event
|
59
|
+
# end
|
60
|
+
|
61
|
+
# def test_sheha_load
|
62
|
+
# sheha = Sheha.new
|
63
|
+
# sheha.load("sheha.yml")
|
64
|
+
# assert sheha.event? Date.new(2012, 12, 25) # Validating against a know configured event
|
65
|
+
# end
|
66
|
+
|
67
|
+
# def test_sheha_config
|
68
|
+
# sheha = Sheha.new
|
69
|
+
# sheha_hash = YAML::load(File.read('sheha.yml'))
|
70
|
+
# sheha.config(sheha_hash)
|
71
|
+
# assert sheha.event? Date.new(2012, 12, 25) # Validating against a know configured event
|
72
|
+
# end
|
73
|
+
|
74
|
+
# def test_sheha_events
|
75
|
+
# sheha = Sheha.new
|
76
|
+
# sheha.add_one_time_event(Date.new(2012, 12, 25)).with_name("Some Name").with_description("Some description")
|
77
|
+
# sheha_hash = sheha.events(Date.new(2012, 12, 25))
|
78
|
+
# assert sheha_hash.is_a? Hash
|
79
|
+
# assert_equal(Date.new(2012, 12, 25), sheha_hash['date'])
|
80
|
+
# assert_equal("Some Name", sheha_hash['name'])
|
81
|
+
# assert_equal("Some description", sheha_hash['description'])
|
82
|
+
# end
|
83
|
+
|
6
84
|
def test_add_event
|
7
85
|
sheha = Sheha.new
|
8
86
|
sheha.add(Sheha::OneTimeEvent.new(Date.new(2012, 12, 25)))
|
data/test/test_sheha_event.rb
CHANGED
@@ -8,6 +8,18 @@ class ShehaEventTest < Test::Unit::TestCase
|
|
8
8
|
assert event.is_a? Sheha::Event
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_event_can_have_name
|
12
|
+
event = Sheha::Event.new 'my_id'
|
13
|
+
event.name = "My Name"
|
14
|
+
assert_equal("My Name", event.name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_event_can_have_name
|
18
|
+
event = Sheha::Event.new 'my_id'
|
19
|
+
event.description = "My Description"
|
20
|
+
assert_equal("My Description", event.description)
|
21
|
+
end
|
22
|
+
|
11
23
|
def test_event_compare_as_equal
|
12
24
|
event = Sheha::Event.new 'my_id'
|
13
25
|
assert_equal(Sheha::Event.new('my_id'), event)
|
@@ -8,6 +8,11 @@ class ShehaYearlyEventTest < Test::Unit::TestCase
|
|
8
8
|
assert event.is_a? Sheha::YearlyEvent
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_new_yearly_event_with_one_digit_month_and_day
|
12
|
+
event = Sheha::YearlyEvent.new(2, 5)
|
13
|
+
assert event.is_a? Sheha::YearlyEvent
|
14
|
+
end
|
15
|
+
|
11
16
|
def test_yearly_event_raise_exception_if_invalid_month
|
12
17
|
assert_raise Sheha::InvalidMonthError do
|
13
18
|
Sheha::YearlyEvent.new(13, 25)
|
@@ -26,6 +31,12 @@ class ShehaYearlyEventTest < Test::Unit::TestCase
|
|
26
31
|
assert_equal(25, event.month_day)
|
27
32
|
end
|
28
33
|
|
34
|
+
def test_yearly_event_has_given_one_digit_month_and_day
|
35
|
+
event = Sheha::YearlyEvent.new(2, 5)
|
36
|
+
assert_equal(2, event.month)
|
37
|
+
assert_equal(5, event.month_day)
|
38
|
+
end
|
39
|
+
|
29
40
|
def test_yearly_event_set_month
|
30
41
|
event = Sheha::YearlyEvent.new(12, 25)
|
31
42
|
event.month = 11
|
@@ -57,11 +68,21 @@ class ShehaYearlyEventTest < Test::Unit::TestCase
|
|
57
68
|
assert_equal(Sheha::YearlyEvent.new(12, 25), event)
|
58
69
|
end
|
59
70
|
|
71
|
+
def test_yearly_event_with_one_digit_month_and_day_compare_as_equal
|
72
|
+
event = Sheha::YearlyEvent.new 2, 5
|
73
|
+
assert_equal(Sheha::YearlyEvent.new(2, 5), event)
|
74
|
+
end
|
75
|
+
|
60
76
|
def test_yearly_event_compare_as_not_equal
|
61
77
|
event = Sheha::YearlyEvent.new 12, 25
|
62
78
|
assert_not_equal(Sheha::YearlyEvent.new(12, 26), event)
|
63
79
|
end
|
64
80
|
|
81
|
+
def test_yearly_event_with_one_digit_month_and_day_compare_as_not_equal
|
82
|
+
event = Sheha::YearlyEvent.new 2, 5
|
83
|
+
assert_not_equal(Sheha::YearlyEvent.new(2, 6), event)
|
84
|
+
end
|
85
|
+
|
65
86
|
def test_yearly_event_eql_and_hash_eval_as_equal
|
66
87
|
set = Set.new
|
67
88
|
set.add Sheha::YearlyEvent.new(12, 25)
|
@@ -81,6 +102,11 @@ class ShehaYearlyEventTest < Test::Unit::TestCase
|
|
81
102
|
assert_equal(Sheha::YearlyEvent.new(12, 26), event.succ)
|
82
103
|
end
|
83
104
|
|
105
|
+
def test_yearly_event_with_one_digit_month_and_day_has_succ
|
106
|
+
event = Sheha::YearlyEvent.new(2, 5)
|
107
|
+
assert_equal(Sheha::YearlyEvent.new(2, 6), event.succ)
|
108
|
+
end
|
109
|
+
|
84
110
|
def test_yearly_events_are_ranges
|
85
111
|
event_1 = Sheha::YearlyEvent.new(12, 25)
|
86
112
|
event_2 = Sheha::YearlyEvent.new(12, 26)
|