hijiri 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hijiri.gemspec +1 -0
- data/lib/hijiri/parser.rb +16 -1
- data/lib/hijiri/version.rb +1 -1
- data/spec/hijiri/parser_spec.rb +59 -0
- data/spec/spec_helper.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b22a31494b32923a5b77125592d3a0c0407033bd
|
4
|
+
data.tar.gz: 39efeea88c7970e4e987db5d6ee3a7b719261440
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d1d6288efe3a6926994f383e9f72af070b3d498a69156c10277c034531d6a492d541bfeb8d20a7ab97939874682856a9ed5eefda899913df7e96bcc2bef19ab
|
7
|
+
data.tar.gz: 988548084cbe0346712f790afbba409be0ac033bf4ce9ed3cca06de6197d3f828124ab417223098ac91366f2fe651b844175f7825b89bef2058387eb40057f6c
|
data/hijiri.gemspec
CHANGED
data/lib/hijiri/parser.rb
CHANGED
@@ -41,6 +41,15 @@ module Hijiri
|
|
41
41
|
.scan(/(?:(?:[\d]+年)?(?:[\d]+月)?(?:[\d]+日)?(?:[\d]+時間?)?(?:[\d]+分)?(?:[\d]+秒)?(?:#{TIMER_WORDS})?)+/)
|
42
42
|
.delete_if(&:blank?)
|
43
43
|
.delete_if{ |word| !word.match(/\d/) }
|
44
|
+
|
45
|
+
if words.blank?
|
46
|
+
begin
|
47
|
+
time = Time.parse(@text)
|
48
|
+
words.push(time.strftime("%Y年%m月%d日 %H時%M分%S秒"))
|
49
|
+
rescue
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
44
53
|
@results = words.map{ |result| Hashie::Mash.new(word: result) }
|
45
54
|
end
|
46
55
|
|
@@ -118,7 +127,7 @@ module Hijiri
|
|
118
127
|
end
|
119
128
|
if n && h.nil? && d.nil? && m.nil? && y.nil? && conv_time(y,m,d,h,n,s) < @current
|
120
129
|
h = @current.hour + 1
|
121
|
-
h =
|
130
|
+
h = 0 if h > 23
|
122
131
|
return point_time(y,m,d,h,n,s)
|
123
132
|
end
|
124
133
|
if s && n.nil? && h.nil? && d.nil? && m.nil? && y.nil? && conv_time(y,m,d,h,n,s) < @current
|
@@ -127,6 +136,12 @@ module Hijiri
|
|
127
136
|
return point_time(y,m,d,h,n,s)
|
128
137
|
end
|
129
138
|
|
139
|
+
s = 0 if s.to_i == 0
|
140
|
+
n = 0 if s.to_i == 0 && n.to_i == 0
|
141
|
+
h = 0 if s.to_i == 0 && n.to_i == 0 && h.to_i == 0
|
142
|
+
d = 1 if s.to_i == 0 && n.to_i == 0 && h.to_i == 0 && d.to_i == 0
|
143
|
+
m = 1 if s.to_i == 0 && n.to_i == 0 && h.to_i == 0 && [0,1].include?(d.to_i) && m.to_i == 0
|
144
|
+
|
130
145
|
conv_time(y,m,d,h,n,s)
|
131
146
|
end
|
132
147
|
|
data/lib/hijiri/version.rb
CHANGED
data/spec/hijiri/parser_spec.rb
CHANGED
@@ -57,6 +57,56 @@ describe Hijiri::Parser do
|
|
57
57
|
expect(result.send(method)).to eq(time.send(method))
|
58
58
|
end
|
59
59
|
end
|
60
|
+
context "年月日時分のみ指定" do
|
61
|
+
it '分のみ指定の場合0秒' do
|
62
|
+
Timecop.travel(2015, 1, 1, 1, 2, 2) do
|
63
|
+
text = "3分"
|
64
|
+
result = Hijiri::Parser.new(text).parse.results.first.datetime
|
65
|
+
expect(result.sec).to eq(0)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
it '時間のみ指定の場合0分' do
|
69
|
+
Timecop.travel(2015, 1, 1, 1, 2) do
|
70
|
+
text = "12時"
|
71
|
+
result = Hijiri::Parser.new(text).parse.results.first.datetime
|
72
|
+
expect(result.min).to eq(0)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
it '日のみ指定の場合0時0分' do
|
76
|
+
Timecop.travel(2015, 1, 1, 1, 2) do
|
77
|
+
text = "2日"
|
78
|
+
result = Hijiri::Parser.new(text).parse.results.first.datetime
|
79
|
+
expect(result.hour).to eq(0)
|
80
|
+
expect(result.min).to eq(0)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
it '付きのみ指定の場合1日0時0分' do
|
84
|
+
Timecop.travel(2015, 1, 1, 1, 2) do
|
85
|
+
text = "12月"
|
86
|
+
result = Hijiri::Parser.new(text).parse.results.first.datetime
|
87
|
+
expect(result.month).to eq(12)
|
88
|
+
expect(result.day).to eq(1)
|
89
|
+
expect(result.hour).to eq(0)
|
90
|
+
expect(result.min).to eq(0)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
it '年のみ指定の場合1日0時0分' do
|
94
|
+
Timecop.travel(2015, 1, 1, 1, 2) do
|
95
|
+
text = "2016年"
|
96
|
+
result = Hijiri::Parser.new(text).parse.results.first.datetime
|
97
|
+
expect(result.month).to eq(1)
|
98
|
+
expect(result.day).to eq(1)
|
99
|
+
expect(result.hour).to eq(0)
|
100
|
+
expect(result.min).to eq(0)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
it "15:00" do
|
105
|
+
text = "15:00"
|
106
|
+
result = Hijiri::Parser.new(text).parse.results.first.datetime
|
107
|
+
expect(result.hour).to eq(15)
|
108
|
+
expect(result.min).to eq(0)
|
109
|
+
end
|
60
110
|
end
|
61
111
|
describe "〜時間後" do
|
62
112
|
it '1時間後' do
|
@@ -130,4 +180,13 @@ describe Hijiri::Parser do
|
|
130
180
|
expect(result[1].datetime.year).to eq(time.next_year.year)
|
131
181
|
end
|
132
182
|
end
|
183
|
+
|
184
|
+
describe "日付表現が含まれない" do
|
185
|
+
it "エラーにならない" do
|
186
|
+
['', '適当な文字列', '1 + 2 = 3'].each do |text|
|
187
|
+
result = Hijiri::Parser.new(text).parse.results
|
188
|
+
expect(result.size).to eq(0)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
133
192
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hijiri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kkosuge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|