hyakunin-issyu 0.1.5 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +3 -1
- data/HyakuninIssyu.gemspec +25 -0
- data/LICENSE.txt +2 -2
- data/README.md +83 -5
- data/Rakefile +9 -0
- data/config/poems.yml +800 -0
- data/config/poets.yml +1000 -0
- data/lib/HyakuninIssyu.rb +180 -0
- data/lib/HyakuninIssyu/version.rb +3 -0
- data/spec/hyakuninissyu_spec.rb +233 -0
- data/spec/spec_helper.rb +34 -3
- metadata +78 -18
- data/hyakunin-issyu.gemspec +0 -19
- data/lib/hyakunin-issyu.rb +0 -23
- data/lib/hyakunin-issyu/data.yml +0 -15
- data/lib/hyakunin-issyu/version.rb +0 -3
@@ -0,0 +1,180 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
class HyakuninIssyu
|
4
|
+
def initialize
|
5
|
+
@@poems = YAML.load_file(File.expand_path(File.join('..', '..', 'config', 'poems.yml'), __FILE__))
|
6
|
+
@@poets = YAML.load_file(File.expand_path(File.join('..', '..', 'config', 'poets.yml'), __FILE__))
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.img_path
|
10
|
+
File.expand_path("../../assets/img", __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def poem(id=nil)
|
14
|
+
return false if id.nil? || id<1 || id>100
|
15
|
+
poem = Poem.new(id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def poet(id=nil)
|
19
|
+
return false if id.nil? || id<1 || id>100
|
20
|
+
poet = Poet.new(id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def poems
|
24
|
+
poems = Array.new
|
25
|
+
for i in 1..100
|
26
|
+
poems[i] = Poem.new(i)
|
27
|
+
end
|
28
|
+
return poems
|
29
|
+
end
|
30
|
+
|
31
|
+
def poets
|
32
|
+
poets = Array.new
|
33
|
+
for i in 1..100
|
34
|
+
poets[i] = Poet.new(i)
|
35
|
+
end
|
36
|
+
return poets
|
37
|
+
end
|
38
|
+
|
39
|
+
class Poem < self
|
40
|
+
def initialize(id)
|
41
|
+
@poem = @@poems[id-1]
|
42
|
+
end
|
43
|
+
|
44
|
+
def id
|
45
|
+
@poem['id']
|
46
|
+
end
|
47
|
+
|
48
|
+
def kana
|
49
|
+
@poem["poem"]["kana"]
|
50
|
+
end
|
51
|
+
|
52
|
+
def kanji
|
53
|
+
@poem["poem"]["kanji"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def en
|
57
|
+
@poem["poem"]["en"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def first
|
61
|
+
First.new(@poem)
|
62
|
+
end
|
63
|
+
|
64
|
+
def last
|
65
|
+
Last.new(@poem)
|
66
|
+
end
|
67
|
+
|
68
|
+
def comment
|
69
|
+
@poem['comment']
|
70
|
+
end
|
71
|
+
|
72
|
+
class First
|
73
|
+
def initialize(data)
|
74
|
+
kanji_data = data["poem"]["kanji"].split(" ")
|
75
|
+
@first_kanji = ''
|
76
|
+
for i in 0..2
|
77
|
+
@first_kanji << kanji_data[i]
|
78
|
+
end
|
79
|
+
|
80
|
+
kana_data = data["poem"]["kana"].split(" ")
|
81
|
+
@first_kana = kana_data[0]
|
82
|
+
|
83
|
+
en_data = data["poem"]["en"].split(" ")
|
84
|
+
@first_en = en_data[0]
|
85
|
+
end
|
86
|
+
|
87
|
+
def kana
|
88
|
+
@first_kana
|
89
|
+
end
|
90
|
+
|
91
|
+
def kanji
|
92
|
+
@first_kanji
|
93
|
+
end
|
94
|
+
|
95
|
+
def en
|
96
|
+
@first_en
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Last
|
101
|
+
def initialize(data)
|
102
|
+
kanji_data = data["poem"]["kanji"].split(" ")
|
103
|
+
@last_kanji = ''
|
104
|
+
for i in 3..4
|
105
|
+
@last_kanji << kanji_data[i]
|
106
|
+
end
|
107
|
+
|
108
|
+
kana_data = data["poem"]["kana"].split(" ")
|
109
|
+
@last_kana = kana_data[1]
|
110
|
+
|
111
|
+
en_data = data["poem"]["en"].split(" ")
|
112
|
+
@last_en = en_data[1]
|
113
|
+
end
|
114
|
+
|
115
|
+
def kana
|
116
|
+
@last_kana
|
117
|
+
end
|
118
|
+
|
119
|
+
def kanji
|
120
|
+
@last_kanji
|
121
|
+
end
|
122
|
+
|
123
|
+
def en
|
124
|
+
@last_en
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Poet < self
|
130
|
+
def initialize(id)
|
131
|
+
@poet = @@poets[id-1]
|
132
|
+
end
|
133
|
+
|
134
|
+
def id
|
135
|
+
@poet['id']
|
136
|
+
end
|
137
|
+
|
138
|
+
def name
|
139
|
+
Name.new(@poet)
|
140
|
+
end
|
141
|
+
|
142
|
+
class Name
|
143
|
+
def initialize(data)
|
144
|
+
@name = data['name']
|
145
|
+
end
|
146
|
+
|
147
|
+
def ja
|
148
|
+
@name['ja']
|
149
|
+
end
|
150
|
+
|
151
|
+
def en
|
152
|
+
@name['en']
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def period
|
157
|
+
@poet['period']
|
158
|
+
end
|
159
|
+
|
160
|
+
def info
|
161
|
+
@poet['info']
|
162
|
+
end
|
163
|
+
|
164
|
+
def male?
|
165
|
+
@poet['sex'] == 1
|
166
|
+
end
|
167
|
+
|
168
|
+
def female?
|
169
|
+
@poet['sex'] == 2
|
170
|
+
end
|
171
|
+
|
172
|
+
def monk?
|
173
|
+
@poet['monk'] == 1
|
174
|
+
end
|
175
|
+
|
176
|
+
def semimaru?
|
177
|
+
@poet['id'] == 10
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
describe HyakuninIssyu do
|
4
|
+
before { @data = HyakuninIssyu.new }
|
5
|
+
describe 'Poem' do
|
6
|
+
before { @poems = YAML.load_file(File.expand_path(File.join('..', '..', 'config', 'poems.yml'), __FILE__)) }
|
7
|
+
|
8
|
+
describe '#id?' do
|
9
|
+
context 'when provided proper id' do
|
10
|
+
before { @poem = @data.poem(3) }
|
11
|
+
it {
|
12
|
+
@poem.id.should be_true
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when provided unproper id' do
|
17
|
+
before { @poem = @data.poem(101) }
|
18
|
+
it {
|
19
|
+
@poem.should be_false
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when provided no id' do
|
24
|
+
before { @poem = @data.poem }
|
25
|
+
it {
|
26
|
+
@poem.should be_false
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with proper poem data' do
|
32
|
+
before { @poem = @data.poem(10) }
|
33
|
+
|
34
|
+
context 'when showing full part' do
|
35
|
+
describe '#kana' do
|
36
|
+
it {
|
37
|
+
@poem.kana.should include_kana
|
38
|
+
}
|
39
|
+
|
40
|
+
it {
|
41
|
+
@poem.kana.split(//u).size.should eq(32)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#kanji' do
|
46
|
+
it {
|
47
|
+
@poem.kanji.should include_kanji
|
48
|
+
}
|
49
|
+
|
50
|
+
it {
|
51
|
+
@poem.kanji.split(/ /).size.should eq(5)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#en' do
|
56
|
+
it {
|
57
|
+
@poem.en.should be_english
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#comment' do
|
62
|
+
it {
|
63
|
+
@poem.comment.should include_kanji
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when showing the first part' do
|
70
|
+
describe '#kana' do
|
71
|
+
it {
|
72
|
+
@poem.first.kana.should include_kana
|
73
|
+
}
|
74
|
+
|
75
|
+
it {
|
76
|
+
@poem.first.kana.split(//u).size.should eq(17)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#kanji' do
|
81
|
+
it {
|
82
|
+
@poem.first.kanji.should include_kanji
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#en' do
|
87
|
+
it {
|
88
|
+
@poem.first.en.should be_english
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when showing the last part' do
|
94
|
+
describe '#kana' do
|
95
|
+
it {
|
96
|
+
@poem.last.kana.should include_kana
|
97
|
+
}
|
98
|
+
|
99
|
+
it {
|
100
|
+
@poem.last.kana.split(//u).size.should eq(14)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#kanji' do
|
105
|
+
it {
|
106
|
+
@poem.last.kanji.should include_kanji
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#en' do
|
111
|
+
it {
|
112
|
+
@poem.last.en.should be_english
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'Poet' do
|
120
|
+
before { @poets = YAML.load_file(File.expand_path(File.join('..', '..', 'config', 'poets.yml'), __FILE__)) }
|
121
|
+
|
122
|
+
describe '#id?' do
|
123
|
+
context 'when provided proper id' do
|
124
|
+
before { @poet = @data.poet(3) }
|
125
|
+
it {
|
126
|
+
@poet.id.should be_true
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when provided unproper id' do
|
131
|
+
before { @poet = @data.poet(101) }
|
132
|
+
it {
|
133
|
+
@poet.should be_false
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when provided no id' do
|
138
|
+
before { @poet = @data.poet }
|
139
|
+
it {
|
140
|
+
@poet.should be_false
|
141
|
+
}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'with proper poet data' do
|
146
|
+
before { @poet = @data.poet(10) }
|
147
|
+
|
148
|
+
describe '#name' do
|
149
|
+
describe '#ja' do
|
150
|
+
it {
|
151
|
+
@poet.name.ja.should include_kanji
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#en' do
|
156
|
+
it {
|
157
|
+
@poet.name.en.should be_english
|
158
|
+
}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#period' do
|
163
|
+
it {
|
164
|
+
@poet.period.should match(/-/)
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#male?' do
|
169
|
+
context 'when poet is male' do
|
170
|
+
before { @poet = @data.poet(1) }
|
171
|
+
it {
|
172
|
+
@poet.male?.should be_true
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when poet is female' do
|
177
|
+
before { @poet = @data.poet(2) }
|
178
|
+
it {
|
179
|
+
@poet.male?.should be_false
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#female?' do
|
185
|
+
context 'when poet is male' do
|
186
|
+
before { @poet = @data.poet(1) }
|
187
|
+
it {
|
188
|
+
@poet.female?.should be_false
|
189
|
+
}
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when poet is female' do
|
193
|
+
before { @poet = @data.poet(2) }
|
194
|
+
it {
|
195
|
+
@poet.female?.should be_true
|
196
|
+
}
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#monk?' do
|
201
|
+
context 'when poet is monk' do
|
202
|
+
before { @poet = @data.poet(8) }
|
203
|
+
it {
|
204
|
+
@poet.monk?.should be_true
|
205
|
+
}
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when poet is not monk' do
|
209
|
+
before { @poet = @data.poet(1) }
|
210
|
+
it {
|
211
|
+
@poet.monk?.should be_false
|
212
|
+
}
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '#semimaru?' do
|
217
|
+
context 'when poet is semimaru' do
|
218
|
+
before { @poet = @data.poet(10) }
|
219
|
+
it {
|
220
|
+
@poet.semimaru?.should be_true
|
221
|
+
}
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'when poet is not semimaru' do
|
225
|
+
before { @poet = @data.poet(1) }
|
226
|
+
it {
|
227
|
+
@poet.semimaru?.should be_false
|
228
|
+
}
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "HyakuninIssyu"
|
4
|
+
require "moji"
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.mock_framework = :rspec
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Matchers.define :include_kanji do |channel, expected_message|
|
11
|
+
match do |str|
|
12
|
+
result = false
|
13
|
+
str.split(//u).each do |char|
|
14
|
+
result = true if Moji.type?(char, Moji::ZEN_KANJI)
|
15
|
+
end
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Matchers.define :include_kana do |channel, expected_message|
|
21
|
+
match do |str|
|
22
|
+
result = false
|
23
|
+
str.split(//u).each do |char|
|
24
|
+
result = true if Moji.type?(char, Moji::ZEN_HIRA)
|
25
|
+
end
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec::Matchers.define :be_english do |channel, expected_message|
|
31
|
+
match do |str|
|
32
|
+
Moji.type?(str, Moji::HAN)
|
33
|
+
end
|
34
|
+
end
|