Hokkaido 0.0.3 → 0.0.4
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.
- data/Gemfile +2 -0
- data/Gemfile.lock +2 -2
- data/ansiterm-color/.gitignore +3 -0
- data/ansiterm-color/CHANGES +28 -0
- data/ansiterm-color/COPYING +340 -0
- data/ansiterm-color/README +137 -0
- data/ansiterm-color/Rakefile +88 -0
- data/ansiterm-color/VERSION +1 -0
- data/ansiterm-color/bin/cdiff +19 -0
- data/ansiterm-color/bin/decolor +12 -0
- data/ansiterm-color/doc-main.txt +119 -0
- data/ansiterm-color/examples/example.rb +90 -0
- data/ansiterm-color/install.rb +15 -0
- data/ansiterm-color/lib/term/ansicolor/.keep +0 -0
- data/ansiterm-color/lib/term/ansicolor/version.rb +10 -0
- data/ansiterm-color/lib/term/ansicolor.rb +102 -0
- data/ansiterm-color/make_doc.rb +4 -0
- data/ansiterm-color/tests/ansicolor_test.rb +66 -0
- data/chronic/.gitignore +6 -0
- data/chronic/HISTORY.md +205 -0
- data/chronic/LICENSE +21 -0
- data/chronic/README.md +181 -0
- data/chronic/Rakefile +46 -0
- data/chronic/chronic.gemspec +20 -0
- data/chronic/lib/chronic/grabber.rb +33 -0
- data/chronic/lib/chronic/handler.rb +88 -0
- data/chronic/lib/chronic/handlers.rb +572 -0
- data/chronic/lib/chronic/mini_date.rb +38 -0
- data/chronic/lib/chronic/numerizer.rb +121 -0
- data/chronic/lib/chronic/ordinal.rb +47 -0
- data/chronic/lib/chronic/pointer.rb +32 -0
- data/chronic/lib/chronic/repeater.rb +145 -0
- data/chronic/lib/chronic/repeaters/repeater_day.rb +53 -0
- data/chronic/lib/chronic/repeaters/repeater_day_name.rb +52 -0
- data/chronic/lib/chronic/repeaters/repeater_day_portion.rb +108 -0
- data/chronic/lib/chronic/repeaters/repeater_fortnight.rb +71 -0
- data/chronic/lib/chronic/repeaters/repeater_hour.rb +58 -0
- data/chronic/lib/chronic/repeaters/repeater_minute.rb +58 -0
- data/chronic/lib/chronic/repeaters/repeater_month.rb +79 -0
- data/chronic/lib/chronic/repeaters/repeater_month_name.rb +94 -0
- data/chronic/lib/chronic/repeaters/repeater_season.rb +109 -0
- data/chronic/lib/chronic/repeaters/repeater_season_name.rb +43 -0
- data/chronic/lib/chronic/repeaters/repeater_second.rb +42 -0
- data/chronic/lib/chronic/repeaters/repeater_time.rb +128 -0
- data/chronic/lib/chronic/repeaters/repeater_week.rb +74 -0
- data/chronic/lib/chronic/repeaters/repeater_weekday.rb +85 -0
- data/chronic/lib/chronic/repeaters/repeater_weekend.rb +66 -0
- data/chronic/lib/chronic/repeaters/repeater_year.rb +77 -0
- data/chronic/lib/chronic/scalar.rb +116 -0
- data/chronic/lib/chronic/season.rb +26 -0
- data/chronic/lib/chronic/separator.rb +94 -0
- data/chronic/lib/chronic/span.rb +31 -0
- data/chronic/lib/chronic/tag.rb +36 -0
- data/chronic/lib/chronic/time_zone.rb +32 -0
- data/chronic/lib/chronic/token.rb +47 -0
- data/chronic/lib/chronic.rb +442 -0
- data/chronic/test/helper.rb +12 -0
- data/chronic/test/test_chronic.rb +150 -0
- data/chronic/test/test_daylight_savings.rb +118 -0
- data/chronic/test/test_handler.rb +104 -0
- data/chronic/test/test_mini_date.rb +32 -0
- data/chronic/test/test_numerizer.rb +72 -0
- data/chronic/test/test_parsing.rb +1061 -0
- data/chronic/test/test_repeater_day_name.rb +51 -0
- data/chronic/test/test_repeater_day_portion.rb +254 -0
- data/chronic/test/test_repeater_fortnight.rb +62 -0
- data/chronic/test/test_repeater_hour.rb +68 -0
- data/chronic/test/test_repeater_minute.rb +34 -0
- data/chronic/test/test_repeater_month.rb +50 -0
- data/chronic/test/test_repeater_month_name.rb +56 -0
- data/chronic/test/test_repeater_season.rb +40 -0
- data/chronic/test/test_repeater_time.rb +70 -0
- data/chronic/test/test_repeater_week.rb +62 -0
- data/chronic/test/test_repeater_weekday.rb +55 -0
- data/chronic/test/test_repeater_weekend.rb +74 -0
- data/chronic/test/test_repeater_year.rb +69 -0
- data/chronic/test/test_span.rb +23 -0
- data/chronic/test/test_token.rb +25 -0
- data/lib/Hokkaido/version.rb +1 -1
- data/lib/Hokkaido.rb +13 -9
- data/lib/gem_modifier.rb +23 -3
- data/lib/term/ansicolor.rb +4 -1
- data/spec/Hokkaido/port_spec.rb +15 -7
- metadata +78 -2
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDaylightSavings < TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@begin_daylight_savings = Time.local(2008, 3, 9, 5, 0, 0, 0)
|
7
|
+
@end_daylight_savings = Time.local(2008, 11, 2, 5, 0, 0, 0)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_begin_past
|
11
|
+
# ambiguous - resolve to last night
|
12
|
+
t = Chronic::RepeaterTime.new('900')
|
13
|
+
t.start = @begin_daylight_savings
|
14
|
+
assert_equal Time.local(2008, 3, 8, 21), t.next(:past).begin
|
15
|
+
|
16
|
+
# ambiguous - resolve to this afternoon
|
17
|
+
t = Chronic::RepeaterTime.new('900')
|
18
|
+
t.start = Time.local(2008, 3, 9, 22, 0, 0, 0)
|
19
|
+
assert_equal Time.local(2008, 3, 9, 21), t.next(:past).begin
|
20
|
+
|
21
|
+
# ambiguous - resolve to this morning
|
22
|
+
t = Chronic::RepeaterTime.new('400')
|
23
|
+
t.start = @begin_daylight_savings
|
24
|
+
assert_equal Time.local(2008, 3, 9, 4), t.next(:past).begin
|
25
|
+
|
26
|
+
# unambiguous - resolve to today
|
27
|
+
t = Chronic::RepeaterTime.new('0400')
|
28
|
+
t.start = @begin_daylight_savings
|
29
|
+
assert_equal Time.local(2008, 3, 9, 4), t.next(:past).begin
|
30
|
+
|
31
|
+
# unambiguous - resolve to yesterday
|
32
|
+
t = Chronic::RepeaterTime.new('1300')
|
33
|
+
t.start = @begin_daylight_savings
|
34
|
+
assert_equal Time.local(2008, 3, 8, 13), t.next(:past).begin
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_begin_future
|
38
|
+
# ambiguous - resolve to this morning
|
39
|
+
t = Chronic::RepeaterTime.new('900')
|
40
|
+
t.start = @begin_daylight_savings
|
41
|
+
assert_equal Time.local(2008, 3, 9, 9), t.next(:future).begin
|
42
|
+
|
43
|
+
# ambiguous - resolve to this afternoon
|
44
|
+
t = Chronic::RepeaterTime.new('900')
|
45
|
+
t.start = Time.local(2008, 3, 9, 13, 0, 0, 0)
|
46
|
+
assert_equal Time.local(2008, 3, 9, 21), t.next(:future).begin
|
47
|
+
|
48
|
+
# ambiguous - resolve to tomorrow
|
49
|
+
t = Chronic::RepeaterTime.new('900')
|
50
|
+
t.start = Time.local(2008, 3, 9, 22, 0, 0, 0)
|
51
|
+
assert_equal Time.local(2008, 3, 10, 9), t.next(:future).begin
|
52
|
+
|
53
|
+
# unambiguous - resolve to today
|
54
|
+
t = Chronic::RepeaterTime.new('0900')
|
55
|
+
t.start = @begin_daylight_savings
|
56
|
+
assert_equal Time.local(2008, 3, 9, 9), t.next(:future).begin
|
57
|
+
|
58
|
+
# unambiguous - resolve to tomorrow
|
59
|
+
t = Chronic::RepeaterTime.new('0400')
|
60
|
+
t.start = @begin_daylight_savings
|
61
|
+
assert_equal Time.local(2008, 3, 10, 4), t.next(:future).begin
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_end_past
|
65
|
+
# ambiguous - resolve to last night
|
66
|
+
t = Chronic::RepeaterTime.new('900')
|
67
|
+
t.start = @end_daylight_savings
|
68
|
+
assert_equal Time.local(2008, 11, 1, 21), t.next(:past).begin
|
69
|
+
|
70
|
+
# ambiguous - resolve to this afternoon
|
71
|
+
t = Chronic::RepeaterTime.new('900')
|
72
|
+
t.start = Time.local(2008, 11, 2, 22, 0, 0, 0)
|
73
|
+
assert_equal Time.local(2008, 11, 2, 21), t.next(:past).begin
|
74
|
+
|
75
|
+
# ambiguous - resolve to this morning
|
76
|
+
t = Chronic::RepeaterTime.new('400')
|
77
|
+
t.start = @end_daylight_savings
|
78
|
+
assert_equal Time.local(2008, 11, 2, 4), t.next(:past).begin
|
79
|
+
|
80
|
+
# unambiguous - resolve to today
|
81
|
+
t = Chronic::RepeaterTime.new('0400')
|
82
|
+
t.start = @end_daylight_savings
|
83
|
+
assert_equal Time.local(2008, 11, 2, 4), t.next(:past).begin
|
84
|
+
|
85
|
+
# unambiguous - resolve to yesterday
|
86
|
+
t = Chronic::RepeaterTime.new('1300')
|
87
|
+
t.start = @end_daylight_savings
|
88
|
+
assert_equal Time.local(2008, 11, 1, 13), t.next(:past).begin
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_end_future
|
92
|
+
# ambiguous - resolve to this morning
|
93
|
+
t = Chronic::RepeaterTime.new('900')
|
94
|
+
t.start = @end_daylight_savings
|
95
|
+
assert_equal Time.local(2008, 11, 2, 9), t.next(:future).begin
|
96
|
+
|
97
|
+
# ambiguous - resolve to this afternoon
|
98
|
+
t = Chronic::RepeaterTime.new('900')
|
99
|
+
t.start = Time.local(2008, 11, 2, 13, 0, 0, 0)
|
100
|
+
assert_equal Time.local(2008, 11, 2, 21), t.next(:future).begin
|
101
|
+
|
102
|
+
# ambiguous - resolve to tomorrow
|
103
|
+
t = Chronic::RepeaterTime.new('900')
|
104
|
+
t.start = Time.local(2008, 11, 2, 22, 0, 0, 0)
|
105
|
+
assert_equal Time.local(2008, 11, 3, 9), t.next(:future).begin
|
106
|
+
|
107
|
+
# unambiguous - resolve to today
|
108
|
+
t = Chronic::RepeaterTime.new('0900')
|
109
|
+
t.start = @end_daylight_savings
|
110
|
+
assert_equal Time.local(2008, 11, 2, 9), t.next(:future).begin
|
111
|
+
|
112
|
+
# unambiguous - resolve to tomorrow
|
113
|
+
t = Chronic::RepeaterTime.new('0400')
|
114
|
+
t.start = @end_daylight_savings
|
115
|
+
assert_equal Time.local(2008, 11, 3, 4), t.next(:future).begin
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestHandler < TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
# Wed Aug 16 14:00:00 UTC 2006
|
7
|
+
@now = Time.local(2006, 8, 16, 14, 0, 0, 0)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_handler_class_1
|
11
|
+
handler = Chronic::Handler.new([:repeater], :handler)
|
12
|
+
|
13
|
+
tokens = [Chronic::Token.new('friday')]
|
14
|
+
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
15
|
+
|
16
|
+
assert handler.match(tokens, Chronic.definitions)
|
17
|
+
|
18
|
+
tokens << Chronic::Token.new('afternoon')
|
19
|
+
tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
20
|
+
|
21
|
+
assert !handler.match(tokens, Chronic.definitions)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_handler_class_2
|
25
|
+
handler = Chronic::Handler.new([:repeater, :repeater?], :handler)
|
26
|
+
|
27
|
+
tokens = [Chronic::Token.new('friday')]
|
28
|
+
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
29
|
+
|
30
|
+
assert handler.match(tokens, Chronic.definitions)
|
31
|
+
|
32
|
+
tokens << Chronic::Token.new('afternoon')
|
33
|
+
tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
34
|
+
|
35
|
+
assert handler.match(tokens, Chronic.definitions)
|
36
|
+
|
37
|
+
tokens << Chronic::Token.new('afternoon')
|
38
|
+
tokens[2].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
39
|
+
|
40
|
+
assert !handler.match(tokens, Chronic.definitions)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_handler_class_3
|
44
|
+
handler = Chronic::Handler.new([:repeater, 'time?'], :handler)
|
45
|
+
|
46
|
+
tokens = [Chronic::Token.new('friday')]
|
47
|
+
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
48
|
+
|
49
|
+
assert handler.match(tokens, Chronic.definitions)
|
50
|
+
|
51
|
+
tokens << Chronic::Token.new('afternoon')
|
52
|
+
tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))
|
53
|
+
|
54
|
+
assert !handler.match(tokens, Chronic.definitions)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_handler_class_4
|
58
|
+
handler = Chronic::Handler.new([:repeater_month_name, :scalar_day, 'time?'], :handler)
|
59
|
+
|
60
|
+
tokens = [Chronic::Token.new('may')]
|
61
|
+
tokens[0].tag(Chronic::RepeaterMonthName.new(:may))
|
62
|
+
|
63
|
+
assert !handler.match(tokens, Chronic.definitions)
|
64
|
+
|
65
|
+
tokens << Chronic::Token.new('27')
|
66
|
+
tokens[1].tag(Chronic::ScalarDay.new(27))
|
67
|
+
|
68
|
+
assert handler.match(tokens, Chronic.definitions)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_handler_class_5
|
72
|
+
handler = Chronic::Handler.new([:repeater, 'time?'], :handler)
|
73
|
+
|
74
|
+
tokens = [Chronic::Token.new('friday')]
|
75
|
+
tokens[0].tag(Chronic::RepeaterDayName.new(:friday))
|
76
|
+
|
77
|
+
assert handler.match(tokens, Chronic.definitions)
|
78
|
+
|
79
|
+
tokens << Chronic::Token.new('5:00')
|
80
|
+
tokens[1].tag(Chronic::RepeaterTime.new('5:00'))
|
81
|
+
|
82
|
+
assert handler.match(tokens, Chronic.definitions)
|
83
|
+
|
84
|
+
tokens << Chronic::Token.new('pm')
|
85
|
+
tokens[2].tag(Chronic::RepeaterDayPortion.new(:pm))
|
86
|
+
|
87
|
+
assert handler.match(tokens, Chronic.definitions)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_handler_class_6
|
91
|
+
handler = Chronic::Handler.new([:scalar, :repeater, :pointer], :handler)
|
92
|
+
|
93
|
+
tokens = [Chronic::Token.new('3'),
|
94
|
+
Chronic::Token.new('years'),
|
95
|
+
Chronic::Token.new('past')]
|
96
|
+
|
97
|
+
tokens[0].tag(Chronic::Scalar.new(3))
|
98
|
+
tokens[1].tag(Chronic::RepeaterYear.new(:year))
|
99
|
+
tokens[2].tag(Chronic::Pointer.new(:past))
|
100
|
+
|
101
|
+
assert handler.match(tokens, Chronic.definitions)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMiniDate < TestCase
|
4
|
+
def test_valid_month
|
5
|
+
assert_raises(ArgumentError){ Chronic::MiniDate.new(0,12) }
|
6
|
+
assert_raises(ArgumentError){ Chronic::MiniDate.new(13,1) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_is_between
|
10
|
+
m=Chronic::MiniDate.new(3,2)
|
11
|
+
assert m.is_between?(Chronic::MiniDate.new(2,4), Chronic::MiniDate.new(4,7))
|
12
|
+
assert !m.is_between?(Chronic::MiniDate.new(1,5), Chronic::MiniDate.new(2,7))
|
13
|
+
|
14
|
+
#There was a hang if date tested is in december and outside the testing range
|
15
|
+
m=Chronic::MiniDate.new(12,24)
|
16
|
+
assert !m.is_between?(Chronic::MiniDate.new(10,1), Chronic::MiniDate.new(12,21))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_is_between_short_range
|
20
|
+
m=Chronic::MiniDate.new(5,10)
|
21
|
+
assert m.is_between?(Chronic::MiniDate.new(5,3), Chronic::MiniDate.new(5,12))
|
22
|
+
assert !m.is_between?(Chronic::MiniDate.new(5,11), Chronic::MiniDate.new(5,15))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_is_between_wrapping_range
|
26
|
+
m=Chronic::MiniDate.new(1,1)
|
27
|
+
assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(2,2))
|
28
|
+
m=Chronic::MiniDate.new(12,12)
|
29
|
+
assert m.is_between?(Chronic::MiniDate.new(11,11), Chronic::MiniDate.new(1,5))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ParseNumbersTest < TestCase
|
4
|
+
|
5
|
+
def test_straight_parsing
|
6
|
+
strings = {
|
7
|
+
'one' => 1,
|
8
|
+
'five' => 5,
|
9
|
+
'ten' => 10,
|
10
|
+
'eleven' => 11,
|
11
|
+
'twelve' => 12,
|
12
|
+
'thirteen' => 13,
|
13
|
+
'fourteen' => 14,
|
14
|
+
'fifteen' => 15,
|
15
|
+
'sixteen' => 16,
|
16
|
+
'seventeen' => 17,
|
17
|
+
'eighteen' => 18,
|
18
|
+
'nineteen' => 19,
|
19
|
+
'twenty' => 20,
|
20
|
+
'twenty seven' => 27,
|
21
|
+
'thirty-one' => 31,
|
22
|
+
'thirty-seven' => 37,
|
23
|
+
'thirty seven' => 37,
|
24
|
+
'fifty nine' => 59,
|
25
|
+
'forty two' => 42,
|
26
|
+
'fourty two' => 42,
|
27
|
+
# 'a hundred' => 100,
|
28
|
+
'one hundred' => 100,
|
29
|
+
'one hundred and fifty' => 150,
|
30
|
+
# 'one fifty' => 150,
|
31
|
+
'two-hundred' => 200,
|
32
|
+
'5 hundred' => 500,
|
33
|
+
'nine hundred and ninety nine' => 999,
|
34
|
+
'one thousand' => 1000,
|
35
|
+
'twelve hundred' => 1200,
|
36
|
+
'one thousand two hundred' => 1_200,
|
37
|
+
'seventeen thousand' => 17_000,
|
38
|
+
'twentyone-thousand-four-hundred-and-seventy-three' => 21_473,
|
39
|
+
'seventy four thousand and two' => 74_002,
|
40
|
+
'ninety nine thousand nine hundred ninety nine' => 99_999,
|
41
|
+
'100 thousand' => 100_000,
|
42
|
+
'two hundred fifty thousand' => 250_000,
|
43
|
+
'one million' => 1_000_000,
|
44
|
+
'one million two hundred fifty thousand and seven' => 1_250_007,
|
45
|
+
'one billion' => 1_000_000_000,
|
46
|
+
'one billion and one' => 1_000_000_001}
|
47
|
+
|
48
|
+
strings.each do |key, val|
|
49
|
+
assert_equal val, Chronic::Numerizer.numerize(key).to_i
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_ordinal_strings
|
54
|
+
{
|
55
|
+
'first' => '1st',
|
56
|
+
'second' => 'second',
|
57
|
+
'second day' => '2nd day',
|
58
|
+
'second of may' => '2nd of may',
|
59
|
+
'fifth' => '5th',
|
60
|
+
'twenty third' => '23rd',
|
61
|
+
'first day month two' => '1st day month 2'
|
62
|
+
}.each do |key, val|
|
63
|
+
# Use pre_normalize here instead of Numerizer directly because
|
64
|
+
# pre_normalize deals with parsing 'second' appropriately
|
65
|
+
assert_equal val, Chronic.pre_normalize(key)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_edges
|
70
|
+
assert_equal "27 Oct 2006 7:30am", Chronic::Numerizer.numerize("27 Oct 2006 7:30am")
|
71
|
+
end
|
72
|
+
end
|