cureutils 0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/cure +4 -0
- data/cureutils.gemspec +26 -0
- data/lib/cureutils/cli.rb +273 -0
- data/lib/cureutils/cure_date_checker.rb +81 -0
- data/lib/cureutils/janken_controller.rb +68 -0
- data/lib/cureutils/version.rb +15 -0
- data/lib/cureutils.rb +2 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d85317471072f1a816290476f494c41c4882783e
|
4
|
+
data.tar.gz: 85310285bf3aae7548b4332a61a325eb42fab8c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6885c95439a8bffca7bf7897affebbcdefdadff3e16b504683f79ce4509f287348c2910906ee57aa732b25b1979710a909244f3f21c95806544830b3d58b9046
|
7
|
+
data.tar.gz: 0948107d8e0db92fe2ec312723f35714d2073e159fb3ec52906316b6eaf3ca4e143465b619bba475b946f615bfa5740def0ff27478d38433c2986f98d4ec1fd0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at yasuhiro.yamada@rakuten.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Yamada, Yasuhiro | Gre | GCSD
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Cureutils
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cureutils`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cureutils'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cureutils
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cureutils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/cure
ADDED
data/cureutils.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cureutils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'cureutils'
|
8
|
+
spec.version = Cureutils::Version
|
9
|
+
spec.authors = ['Yamada, Yasuhiro']
|
10
|
+
spec.email = ['greengregson@gmail.com']
|
11
|
+
spec.summary = 'Useful commands for battle heroine "Pretty Cure (Precure)".'
|
12
|
+
spec.description = 'Commands which can smoothly deal with Precure-related data.'
|
13
|
+
spec.homepage = 'https://github.com/greymd/cureutils'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'bin'
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
21
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
22
|
+
spec.add_dependency 'thor', ['>= 0.19.1', '< 2']
|
23
|
+
spec.add_dependency 'rubicure', '~> 0.4.4'
|
24
|
+
spec.add_dependency 'colorize', '~> 0.7.7'
|
25
|
+
spec.add_dependency 'activesupport', '~> 4.2.6'
|
26
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'cureutils/version'
|
3
|
+
require 'cureutils/janken_controller'
|
4
|
+
require 'cureutils/cure_date_checker'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/time'
|
7
|
+
require 'time'
|
8
|
+
require 'thor'
|
9
|
+
require 'rubicure'
|
10
|
+
require 'colorize'
|
11
|
+
|
12
|
+
module Cureutils
|
13
|
+
module EchoMode
|
14
|
+
TRANSFORM = 1
|
15
|
+
ATTACK = 2
|
16
|
+
end
|
17
|
+
#
|
18
|
+
# The class represents the cli interface
|
19
|
+
#
|
20
|
+
class CLI < Thor
|
21
|
+
class << self
|
22
|
+
def exit_on_failure?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'transform', 'Change human_name to precure_name'
|
28
|
+
def transform
|
29
|
+
print_converted_text($stdin, :human_name, :precure_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'humanize', 'Change precure_name to human_name'
|
33
|
+
def humanize
|
34
|
+
print_converted_text($stdin, :precure_name, :human_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'girls', 'Print girls\' name'
|
38
|
+
def girls
|
39
|
+
Rubicure::Girl.config.map { |_k, v| v[:human_name] }.uniq.each do |v|
|
40
|
+
puts v
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'precures', 'Print Precures\' name'
|
45
|
+
def precures
|
46
|
+
Rubicure::Girl.config.map { |_k, v| v[:precure_name] }.uniq.each do |v|
|
47
|
+
puts v
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'mytest', 'print arguments.'
|
52
|
+
option 'reduce', aliases: 'r'
|
53
|
+
def mytest(arg1 = 'arg1', fname = nil)
|
54
|
+
optstr = options[:reduce] ? options[:reduce] : 'empty'
|
55
|
+
@io = $stdout
|
56
|
+
@io.puts 'opt:' + optstr
|
57
|
+
@io.puts 'arg1:' + arg1
|
58
|
+
@io.puts 'fname:' + (fname ? fname : 'stdin')
|
59
|
+
@input = input_from(fname)
|
60
|
+
@input.each { |line| puts 'cap: ' + line }
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'grep [OPTIONS] PATTERN', 'print lines matching a pattern.'
|
64
|
+
option 'extended-regexp', aliases: 'E'
|
65
|
+
option 'only-matching', aliases: 'o'
|
66
|
+
def grep(pat = '[:precure_name:]', filename = nil)
|
67
|
+
# Check whether the file is given or not
|
68
|
+
@input = input_from(filename)
|
69
|
+
extended_pat = options['extended-regexp'.to_sym]
|
70
|
+
if extended_pat
|
71
|
+
cure_pat = extended_pat
|
72
|
+
else
|
73
|
+
cure_pat = pregex2regex(pat)
|
74
|
+
end
|
75
|
+
# Check the file discriptor and check the pipe exists or not.
|
76
|
+
pipe_flg = !$stdout.isatty
|
77
|
+
if options['only-matching'.to_sym]
|
78
|
+
if pipe_flg
|
79
|
+
@input.each do |line|
|
80
|
+
matched_strs = line.scan(/#{cure_pat}/)
|
81
|
+
matched_strs.empty? || matched_strs.each do |str|
|
82
|
+
puts str
|
83
|
+
end
|
84
|
+
end
|
85
|
+
else
|
86
|
+
@input.each do |line|
|
87
|
+
matched_strs = line.scan(/#{cure_pat}/)
|
88
|
+
matched_strs.empty? || matched_strs.each do |str|
|
89
|
+
puts str.red
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
else
|
94
|
+
if pipe_flg
|
95
|
+
@input.each do |line|
|
96
|
+
puts line.gsub(/#{cure_pat}/, '\0') if line =~ /#{cure_pat}/
|
97
|
+
end
|
98
|
+
else
|
99
|
+
@input.each do |line|
|
100
|
+
puts line.gsub(/#{cure_pat}/, '\0'.red) if line =~ /#{cure_pat}/
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
desc 'tr PATTERN REPLACE', 'Extract precure name or other related params.'
|
107
|
+
def tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]')
|
108
|
+
pat_from = pregex2str(pat_from).to_sym
|
109
|
+
pat_to = pregex2str(pat_to).to_sym
|
110
|
+
print_converted_text($stdin, pat_from, pat_to)
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'echo PATTERN', 'Extract precure name or other related params.'
|
114
|
+
option 'quick', aliases: 'q',
|
115
|
+
type: :boolean,
|
116
|
+
desc: 'Print messages immediately.'
|
117
|
+
option 'attack', aliases: 'a',
|
118
|
+
type: :boolean, desc: 'Print attack message.'
|
119
|
+
option 'transform', aliases: 't',
|
120
|
+
type: :boolean, desc: 'Print transform message.'
|
121
|
+
option 'precure', aliases: 'p',
|
122
|
+
type: :string, desc: "Print the given PRECURE's message."
|
123
|
+
def echo
|
124
|
+
cure_name = options[:precure] || 'echo'
|
125
|
+
message_mode = EchoMode::TRANSFORM
|
126
|
+
message_mode = EchoMode::TRANSFORM if options[:transform]
|
127
|
+
message_mode = EchoMode::ATTACK if options[:attack]
|
128
|
+
Rubicure::Girl.sleep_sec = 0 if options[:quick]
|
129
|
+
cure = Rubicure::Girl.config.find { |k, _v| k == cure_name.to_sym }
|
130
|
+
unless cure
|
131
|
+
$stderr.puts "No such precure #{cure_name}"
|
132
|
+
exit(1)
|
133
|
+
end
|
134
|
+
if message_mode == EchoMode::TRANSFORM
|
135
|
+
Cure.send(cure_name.to_sym).transform!
|
136
|
+
elsif message_mode == EchoMode::ATTACK
|
137
|
+
Cure.send(cure_name.to_sym).transform!
|
138
|
+
Cure.send(cure_name.to_sym).attack!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
desc 'date [OPTIONS] [+FORMAT]',
|
143
|
+
'Extract precure name or other related params.'
|
144
|
+
option 'date', aliases: 'd'
|
145
|
+
# Original date command's default is '+%a %b %e %H:%M:%S %Z %Y @P'
|
146
|
+
# However, I would like to adopt this setting.
|
147
|
+
def date(fmt = '+%F %H:%M:%S @P')
|
148
|
+
# -d, --date=STRING (YYYY-MM-DD or +-N days)
|
149
|
+
print_time = create_time_obj(options[:date])
|
150
|
+
updated_fmt = update_fmt(print_time, fmt)
|
151
|
+
puts print_time.strftime(updated_fmt)
|
152
|
+
end
|
153
|
+
|
154
|
+
desc 'janken', %Q(Let's play "Pikarin Janken" !)
|
155
|
+
def janken
|
156
|
+
judge = JankenContoller.janken
|
157
|
+
exit(judge.to_i)
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def input_from(filename)
|
163
|
+
if filename.nil? || filename.empty?
|
164
|
+
output = $stdin
|
165
|
+
elsif filename =~ /^-$/
|
166
|
+
# If the file name is "-", use STDIN.
|
167
|
+
output = $stdin
|
168
|
+
else
|
169
|
+
begin
|
170
|
+
output = File.open(filename)
|
171
|
+
rescue SystemCallError => e
|
172
|
+
puts %(class=[#{e.class}] message=[#{e.message}])
|
173
|
+
rescue IOError => e
|
174
|
+
puts %(class=[#{e.class}] message=[#{e.message}])
|
175
|
+
end
|
176
|
+
end
|
177
|
+
output
|
178
|
+
end
|
179
|
+
|
180
|
+
def update_fmt(datetime, fmt)
|
181
|
+
# Find precure related events
|
182
|
+
date4check_event = time2date(datetime)
|
183
|
+
found_event = CureDateChecker.events(date4check_event)
|
184
|
+
checked_fmt = fmt
|
185
|
+
if fmt =~ /^\+(.*)$/
|
186
|
+
checked_fmt = Regexp.last_match(1)
|
187
|
+
else
|
188
|
+
puts "cure date: invalid date format '#{fmt}'"
|
189
|
+
exit 1
|
190
|
+
end
|
191
|
+
# Find precure related events
|
192
|
+
checked_fmt.gsub(/@P/, found_event)
|
193
|
+
end
|
194
|
+
|
195
|
+
def create_time_obj(time_str)
|
196
|
+
time_str ? natural_lang2time(time_str) : Time.now
|
197
|
+
end
|
198
|
+
|
199
|
+
def natural_lang2time(time_str)
|
200
|
+
updated_fmt = time_str.dup
|
201
|
+
updated_fmt.gsub!(/yesterday/, '1 day ago')
|
202
|
+
updated_fmt.gsub!(/tomorrow/, '-1 day ago')
|
203
|
+
units = 'second|minute|hour|day|week|month|year'
|
204
|
+
regulated_format = /(-?[0-9]+) *(#{units})s? *(ago)?/
|
205
|
+
if updated_fmt =~ regulated_format
|
206
|
+
diff_value = Regexp.last_match(1).to_i
|
207
|
+
unit = Regexp.last_match(2).to_sym
|
208
|
+
minus_flg = Regexp.last_match(3)
|
209
|
+
if minus_flg.nil?
|
210
|
+
Time.now + diff_value.send(unit)
|
211
|
+
else
|
212
|
+
Time.now - diff_value.send(unit)
|
213
|
+
end
|
214
|
+
else
|
215
|
+
Time.parse(updated_fmt)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
desc 'pregex2regex', 'Convert string to precure regular expression'
|
220
|
+
def pregex2regex(regex, br_flg = false)
|
221
|
+
this_regex = regex.dup
|
222
|
+
br_ex = br_flg ? '' : '?:'
|
223
|
+
%w(girl_name human_name precure_name cast_name color).each do |attr|
|
224
|
+
expression = '\[:' + attr + ':\]'
|
225
|
+
precures_ex = cure_list(attr.to_sym).join('|')
|
226
|
+
replaced = "(#{br_ex}#{precures_ex})"
|
227
|
+
this_regex.gsub!(/#{expression}/, replaced)
|
228
|
+
end
|
229
|
+
this_regex
|
230
|
+
end
|
231
|
+
|
232
|
+
def str2pregex(str)
|
233
|
+
'[:' + str + ':]'
|
234
|
+
end
|
235
|
+
|
236
|
+
def pregex2str(str)
|
237
|
+
str.gsub(/\[:(.*):\]/, '\1')
|
238
|
+
end
|
239
|
+
|
240
|
+
def cure_list(sym)
|
241
|
+
list = Precure.all_stars.map(&sym)
|
242
|
+
list << Cure.echo[sym]
|
243
|
+
list
|
244
|
+
end
|
245
|
+
|
246
|
+
def cure_table(to_sym, from_sym)
|
247
|
+
to_arr = cure_list(to_sym)
|
248
|
+
from_arr = cure_list(from_sym)
|
249
|
+
hash = Hash[[to_arr, from_arr].transpose]
|
250
|
+
hash
|
251
|
+
end
|
252
|
+
|
253
|
+
def time2date(timeObj)
|
254
|
+
Date.parse(timeObj.strftime('%Y-%m-%d'))
|
255
|
+
end
|
256
|
+
|
257
|
+
def print_converted_text(input, from_sym, to_sym)
|
258
|
+
# Create precure regular expression
|
259
|
+
regex_tag = str2pregex(from_sym.to_s)
|
260
|
+
# Get patterns
|
261
|
+
cure_pattern = pregex2regex(regex_tag, true)
|
262
|
+
# Get Key-Value
|
263
|
+
table = cure_table(from_sym, to_sym)
|
264
|
+
input.each do |line|
|
265
|
+
updated_line = line.dup
|
266
|
+
line.scan(/#{cure_pattern}/).each do |pat|
|
267
|
+
updated_line.gsub!(/#{pat[0]}/, table[pat[0]])
|
268
|
+
end
|
269
|
+
puts updated_line
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'date'
|
3
|
+
#
|
4
|
+
# Date class supports the precure format
|
5
|
+
#
|
6
|
+
class CureDateChecker
|
7
|
+
class << self
|
8
|
+
def events(date)
|
9
|
+
create_hash
|
10
|
+
event_list = [birth_date?(date),
|
11
|
+
created_date?(date),
|
12
|
+
movie_date?(date),
|
13
|
+
series_between(date)].compact
|
14
|
+
event_list.join('/')
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def create_hash
|
20
|
+
hashize_cure_date unless @birth_date || @created_date
|
21
|
+
hashize_movie_date unless @movie_started_date
|
22
|
+
end
|
23
|
+
|
24
|
+
def birth_date?(date)
|
25
|
+
date_str = date.strftime('%m/%d')
|
26
|
+
result = @birth_date[date_str]
|
27
|
+
# format
|
28
|
+
result.nil? ? nil : "#{result[:human_name]}(#{result[:precure_name]})誕生日"
|
29
|
+
end
|
30
|
+
|
31
|
+
def created_date?(date)
|
32
|
+
date_str = date.strftime('%m/%d')
|
33
|
+
result = @created_date[date_str]
|
34
|
+
# format
|
35
|
+
result.nil? ? nil : "#{result[:precure_name]}初登場日"
|
36
|
+
end
|
37
|
+
|
38
|
+
def movie_date?(date)
|
39
|
+
result = @created_date[date]
|
40
|
+
# format
|
41
|
+
result.nil? ? nil : "#{result[:title]}映画公開日"
|
42
|
+
end
|
43
|
+
|
44
|
+
def series_between(date)
|
45
|
+
event_name = nil
|
46
|
+
Rubicure::Series.config.each do |_k, v|
|
47
|
+
if v[:started_date] == date
|
48
|
+
event_name = "#{v[:title]}初放映"
|
49
|
+
break
|
50
|
+
end
|
51
|
+
if v[:ended_date] == date
|
52
|
+
event_name = "#{v[:title]}最終回"
|
53
|
+
break
|
54
|
+
end
|
55
|
+
# Nobody expects the future. Precure series may be abolished today.
|
56
|
+
v[:ended_date] = Date.today + 1 if v[:ended_date].nil?
|
57
|
+
if v[:started_date] < date && date < v[:ended_date]
|
58
|
+
event_name = "#{v[:title]}放映期間"
|
59
|
+
break
|
60
|
+
end
|
61
|
+
end
|
62
|
+
event_name
|
63
|
+
end
|
64
|
+
|
65
|
+
def hashize_cure_date
|
66
|
+
@birth_date = {}
|
67
|
+
@created_date = {}
|
68
|
+
Rubicure::Girl.config.map do |_k, v|
|
69
|
+
v[:birthday].nil? || @birth_date[v[:birthday]] = v
|
70
|
+
v[:created_date].nil? || @created_date[v[:created_date]] = v
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def hashize_movie_date
|
75
|
+
@movie_started_date = {}
|
76
|
+
Rubicure::Movie.config.map do |_k, v|
|
77
|
+
v[:started_date].nil? || @movie_started_date[v[:started_date]] = v
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# Wrapper class of Pikarin Janken
|
4
|
+
#
|
5
|
+
class JankenContoller
|
6
|
+
class << self
|
7
|
+
def initialize
|
8
|
+
# Set the sleep time 0
|
9
|
+
Rubicure::Girl.sleep_sec = 0
|
10
|
+
# 0: win, 1: lose, 2: aiko
|
11
|
+
@result_table = [[2, 0, 1, 1],
|
12
|
+
[1, 2, 0, 1],
|
13
|
+
[0, 1, 2, 1],
|
14
|
+
[0, 0, 0, 2]]
|
15
|
+
@result_idx = %w(あなたのかち あなたのまけ あいこ)
|
16
|
+
@te_idx = %w(グー チョキ パー グッチョッパー)
|
17
|
+
@te_hash = Hash[[@te_idx, (0..3).map(&:to_s)].transpose]
|
18
|
+
@buf = []
|
19
|
+
@io = $stdout
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_writer :io
|
23
|
+
|
24
|
+
def puts(input)
|
25
|
+
@buf << input
|
26
|
+
end
|
27
|
+
|
28
|
+
def janken
|
29
|
+
initialize
|
30
|
+
Cure.peace.io = self
|
31
|
+
Cure.peace.janken
|
32
|
+
@buf[0..1].each do |msg|
|
33
|
+
@io.puts msg
|
34
|
+
end
|
35
|
+
judge
|
36
|
+
end
|
37
|
+
|
38
|
+
def generated_te
|
39
|
+
@buf.last =~ /(#{@te_idx.join('|')})/
|
40
|
+
@te_hash[Regexp.last_match(1)].to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
def input_te
|
44
|
+
@io.print("1...グー, 2...チョキ, 3...パー : ")
|
45
|
+
# TODO: Check input and raise the error.
|
46
|
+
player_te = $stdin.gets
|
47
|
+
player_te.to_i - 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def judge
|
51
|
+
cure_te = generated_te
|
52
|
+
player_te = input_te
|
53
|
+
result_num = @result_table[player_te][cure_te]
|
54
|
+
result = @result_idx[result_num]
|
55
|
+
print_results(@te_idx[player_te], @te_idx[cure_te], result)
|
56
|
+
result_num
|
57
|
+
end
|
58
|
+
|
59
|
+
def print_results(player_te, cure_te, result)
|
60
|
+
@io.puts
|
61
|
+
@io.puts 'あなた: ' + player_te
|
62
|
+
@io.puts 'キュアピース: ' + cure_te
|
63
|
+
@io.puts
|
64
|
+
@io.puts '[結果]'
|
65
|
+
@io.puts result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/cureutils.rb
ADDED
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cureutils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yamada, Yasuhiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.19.1
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.19.1
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubicure
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.4.4
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.4.4
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: colorize
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.7.7
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.7.7
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: activesupport
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 4.2.6
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 4.2.6
|
117
|
+
description: Commands which can smoothly deal with Precure-related data.
|
118
|
+
email:
|
119
|
+
- greengregson@gmail.com
|
120
|
+
executables:
|
121
|
+
- cure
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- ".gitignore"
|
126
|
+
- ".rspec"
|
127
|
+
- ".travis.yml"
|
128
|
+
- CODE_OF_CONDUCT.md
|
129
|
+
- Gemfile
|
130
|
+
- LICENSE.txt
|
131
|
+
- README.md
|
132
|
+
- Rakefile
|
133
|
+
- bin/cure
|
134
|
+
- cureutils.gemspec
|
135
|
+
- lib/cureutils.rb
|
136
|
+
- lib/cureutils/cli.rb
|
137
|
+
- lib/cureutils/cure_date_checker.rb
|
138
|
+
- lib/cureutils/janken_controller.rb
|
139
|
+
- lib/cureutils/version.rb
|
140
|
+
homepage: https://github.com/greymd/cureutils
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.4.5
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Useful commands for battle heroine "Pretty Cure (Precure)".
|
164
|
+
test_files: []
|