cureutils 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c94e405b6e4fed704753438ad76eaeca68d1f22
4
- data.tar.gz: eb001cd954852d147ac6af02646e00cb35ce4a66
3
+ metadata.gz: c34da5a7a9fce98a5f8314e7d61cad556629c6f0
4
+ data.tar.gz: ed11bee62896aa13fac07861429e124a59c97f9d
5
5
  SHA512:
6
- metadata.gz: 761291e67ac30982fd63fc64af936b26579a2bf4f3fc753ecaa44231437ee458e895d44fd40c5cc2444fdf7959c3fd98597d6b70a441ec51f24caf521bafa348
7
- data.tar.gz: 3ed00dbb643d140ae100ebf32cc55a11b93b4ae6db0c11a66d14d28adc942398859bef12d0297d02ef868537eacd1db50d11c58517bba415d1993b4457719349
6
+ metadata.gz: 943b29cfd42f50375593689d021eb89778d627bc27292128e8a5098b2982d12e274adfd1fbd955b9f1540655cf023915dfbbcfe3bb090b07c4ed989f0f0028e4
7
+ data.tar.gz: 880578332edaf71257b36eb70ef5f1812ff4af600791188a307f928361bce2f2a1dd800c13f37b097f09d2f2a1875e5858f6a4246d41fa8d3885138525991737
data/.travis.yml CHANGED
@@ -1,4 +1,26 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.2.0
4
- before_install: gem install bundler -v 1.11.2
4
+ - 2.2.2
5
+ - 2.3.3
6
+ - 2.4.0
7
+ - ruby-head
8
+
9
+ before_install:
10
+ - gem update --system --no-document
11
+ - gem install bundler -v 1.11.2
12
+ - bundle install
13
+
14
+ branches:
15
+ only:
16
+ - master
17
+ - develop-1.0.0
18
+
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+
23
+ sudo: false
24
+
25
+ script:
26
+ - bash test/test.sh
data/Gemfile CHANGED
@@ -3,10 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in cureutils.gemspec
4
4
  gemspec
5
5
 
6
- if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.3.0")
7
- gem "backport_dig"
8
- end
9
-
10
- if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.2")
11
- gem "activesupport", ">= 4.0.0", "< 5.0.0"
6
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.create('2.3.0')
7
+ gem 'backport_dig'
12
8
  end
data/README.md CHANGED
@@ -4,14 +4,27 @@
4
4
 
5
5
  # Cureutils
6
6
  [![Gem Version](https://badge.fury.io/rb/cureutils.svg)](https://badge.fury.io/rb/cureutils)
7
+ [![Build Status](https://travis-ci.org/greymd/cureutils.svg?branch=master)](https://travis-ci.org/greymd/cureutils)
7
8
 
8
9
  Useful command line tool for Japanese battle heroine Pretty Cure (Precure).
9
10
 
11
+ ![completion_image](./img/cure_echo_demo.gif)
12
+
13
+ ## Requirements
14
+
15
+ * ruby >= 2.2.2
16
+ + more: [.travis.yml](./.travis.yml)
17
+
10
18
  ## Installation
11
19
 
12
20
  Install:
13
21
 
14
- $ gem install cureutils
22
+ ```
23
+ $ gem install cureutils
24
+
25
+ # for 2.2
26
+ $ gem install 'backport_dig'
27
+ ```
15
28
 
16
29
 
17
30
  After that, `cure` command is available.
@@ -61,15 +74,32 @@ And other general date formats are usable.
61
74
 
62
75
  ### Options
63
76
 
64
- | Option | Description |
65
- | ------ | --------- |
66
- | -d | cure date -d STRING: display time described by STRING |
77
+ | Option | Description |
78
+ | ------ | --------- |
79
+ | -d | cure date -d STRING: display time described by STRING |
80
+ | -f | cure date -f DATEFILE: Load each line of DATEFILE as STRING of -d option. |
67
81
 
68
82
  ```sh
69
83
  $ cure date -d '3 years ago' '+%Y/%m @P'
70
84
  2013/06 ドキドキ!プリキュア放映期間
71
85
  ```
72
86
 
87
+ Standard input can be loaded by giving `-` as DATEFILE.
88
+
89
+ ```sh
90
+ $ echo 2016{01..12}{01..31}| xargs -n 1 | cure date -f - '+%F @P' 2>/dev/null | grep 誕生日 | head
91
+ 2016-01-07 宇佐美いちか(キュアホイップ)誕生日/Go!プリンセスプリキュア放映期間
92
+ 2016-04-04 雪城ほのか(キュアホワイト)誕生日/魔法つかいプリキュア!放映期間
93
+ 2016-04-10 春野はるか(キュアフローラ)誕生日/魔法つかいプリキュア!放映期間
94
+ 2016-04-16 有栖川ひまり(キュアカスタード)誕生日/魔法つかいプリキュア!放映期間
95
+ 2016-05-28 四葉ありす(キュアロゼッタ)誕生日/魔法つかいプリキュア!放映期間
96
+ 2016-06-11 琴爪ゆかり(キュアマカロン)誕生日/魔法つかいプリキュア!放映期間
97
+ 2016-06-12 朝日奈みらい(キュアミラクル)誕生日/魔法つかいプリキュア!放映期間
98
+ 2016-07-20 海藤みなみ(キュアマーメイド)誕生日/魔法つかいプリキュア!放映期間
99
+ 2016-08-04 相田マナ(キュアハート)誕生日/魔法つかいプリキュア!放映期間
100
+ 2016-08-07 日向咲(キュアブルーム)誕生日/魔法つかいプリキュア!放映期間
101
+ ```
102
+
73
103
  ## `cure echo`
74
104
  Print messages of Precure.
75
105
 
@@ -90,15 +120,23 @@ $ cure echo -p happy
90
120
  キラキラ輝く未来の光! キュアハッピー!
91
121
  5つの光が導く未来!
92
122
  輝け!スマイルプリキュア!
123
+
124
+ # Choose style for MAHO GIRLS PRECURE!
125
+ $ cure echo -p cure_magical -s ruby
126
+ キュアップ・ラパパ! ルビー!
127
+ ミラクル・マジカル・ジュエリーレ!
128
+ ふたりの魔法!キュアマジカル!
129
+ 魔法つかいプリキュア!!
93
130
  ```
94
131
 
95
132
  ### Options
96
133
 
97
- | Option | Description |
98
- | ------ | ----------- |
99
- | -a | Print attack message. |
100
- | -q | Print messages immediately. |
101
- | -p | Print the given PRECURE's message. |
134
+ | Option | Description |
135
+ | ------ | ----------- |
136
+ | -a | Print attack message. |
137
+ | -q | Print messages immediately. |
138
+ | -p | Print the given PRECURE's message. |
139
+ | -s | Choose style of the transformation. |
102
140
 
103
141
 
104
142
  ## `cure girls`
@@ -121,7 +159,7 @@ $ cure girls
121
159
 
122
160
  | Option | Description |
123
161
  | ------ | ----------- |
124
- | -v | Include particular girl's full name. |
162
+ | -f | Show girl's full name if it exists. |
125
163
  | -m | Include who have only appeared in the movies. |
126
164
 
127
165
 
@@ -246,10 +284,19 @@ $ cure precures
246
284
 
247
285
  [zsh-completion/_cure](zsh-completion/_cure) is the file for `cure` command completion.
248
286
  With [zplug](https://github.com/zplug/zplug), it can be installed like this.
287
+
288
+ ```sh
289
+ zplug "greymd/cureutils"
290
+ ```
291
+
292
+ And update like this.
293
+
249
294
  ```sh
250
- zplug "greymd/cureutils", use:cureutils.plugin.zsh
295
+ $ zplug update greymd/cureutils
251
296
  ```
252
297
 
298
+ ![completion_image](./img/cure_echo_demo.gif)
299
+
253
300
  ## Contributing
254
301
 
255
302
  Bug reports and pull requests are welcome on GitHub at https://github.com/greymd/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.
data/cureutils.gemspec CHANGED
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
16
16
  spec.bindir = 'bin'
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ['lib']
19
- spec.required_ruby_version = '>= 2.0.0'
19
+ spec.required_ruby_version = '>= 2.2.2'
20
20
  spec.add_development_dependency 'bundler', '~> 1.11'
21
21
  spec.add_development_dependency 'rake', '~> 10.0'
22
22
  spec.add_development_dependency 'rspec', '~> 3.0'
23
23
  spec.add_dependency 'thor', ['>= 0.19.1', '< 2']
24
- spec.add_dependency 'rubicure', '~> 0.4'
24
+ spec.add_dependency 'rubicure', '~> 1.0.0'
25
25
  spec.add_dependency 'colorize', '~> 0.7.7'
26
- spec.add_dependency 'activesupport', '~> 4.2.6'
26
+ spec.add_dependency 'activesupport', '>= 5.0.0'
27
27
  end
data/cureutils.plugin.zsh CHANGED
@@ -1 +1,3 @@
1
- fpath+="`dirname $0`/zsh-completion"
1
+ _CURE_DIR="$(dirname $0:A)"
2
+ # Import completion
3
+ fpath+="${_CURE_DIR}/zsh-completion"
Binary file
data/lib/cureutils.rb CHANGED
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  require 'cureutils/version'
2
3
  require 'cureutils/cli'
data/lib/cureutils/cli.rb CHANGED
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
2
3
  require 'cureutils/version'
3
4
  require 'cureutils/common'
4
- require 'cureutils/cure_janken_manager'
5
- require 'cureutils/cure_date_manager'
6
- require 'cureutils/cure_grep_manager'
7
- require 'cureutils/cure_echo_manager'
8
- require 'cureutils/cure_translate_manager'
5
+ require 'cureutils/logic/janken_logic'
6
+ require 'cureutils/logic/date_logic'
7
+ require 'cureutils/logic/grep_logic'
8
+ require 'cureutils/logic/echo_logic'
9
+ require 'cureutils/logic/translate_logic'
9
10
  require 'active_support'
10
11
  require 'active_support/time'
11
12
  require 'time'
@@ -31,38 +32,38 @@ module Cureutils
31
32
 
32
33
  desc 'transform', 'Change human_name to precure_name.'
33
34
  def transform
34
- manager = CureTranslateManager.new
35
- manager.translate_from_to('[:human_name:]', '[:precure_name:]')
36
- manager.in = $stdin
37
- exit(manager.print_results)
35
+ logic = TranslateLogic.new
36
+ logic.translate_from_to('[:human_name:]', '[:precure_name:]')
37
+ logic.in = $stdin
38
+ exit(logic.print_results)
38
39
  end
39
40
 
40
41
  desc 'humanize', 'Change precure_name to human_name.'
41
42
  def humanize
42
- manager = CureTranslateManager.new
43
- manager.translate_from_to('[:precure_name:]', '[:human_name:]')
44
- manager.in = $stdin
45
- exit(manager.print_results)
43
+ logic = TranslateLogic.new
44
+ logic.translate_from_to('[:precure_name:]', '[:human_name:]')
45
+ logic.in = $stdin
46
+ exit(logic.print_results)
46
47
  end
47
48
 
48
49
  desc 'girls [OPTIONS]', "Print girls' name."
49
- option 'verbose', aliases: 'v',
50
+ # In order to keep backward compatibility, v option is still remaining.
51
+ option 'full-name', aliases: 'f',
50
52
  type: :boolean,
51
- desc: "Include particular girl's full name."
53
+ desc: "Show girl's full name if it exists."
52
54
  option 'movie', aliases: 'm',
53
55
  type: :boolean,
54
56
  desc: 'Include who have only appeared in the movies.'
55
57
  def girls
56
- girls = Precure.all_stars
57
- girls = girls << Cure.echo if options[:movie]
58
- girls.map!(&:human_name)
59
- if options[:verbose]
58
+ girls = Precure.all_girls
59
+ girls.delete(Cure.echo) unless options[:movie]
60
+ if options['full-name'.to_sym]
60
61
  girls.each do |v|
61
- puts v
62
+ puts v.full_name
62
63
  end
63
64
  else
64
65
  girls.each do |v|
65
- puts v.gsub(/\([^\)]+\)$/, '')
66
+ puts v.human_name
66
67
  end
67
68
  end
68
69
  end
@@ -72,8 +73,8 @@ module Cureutils
72
73
  type: :boolean,
73
74
  desc: 'Include who have only appeared in the movies.'
74
75
  def precures
75
- cures = Precure.all_stars
76
- cures = cures << Cure.echo if options[:movie]
76
+ cures = Precure.all_girls
77
+ cures.delete(Cure.echo) unless options[:movie]
77
78
  cures.map!(&:precure_name)
78
79
  cures.each do |v|
79
80
  puts v
@@ -88,22 +89,22 @@ module Cureutils
88
89
  type: :boolean,
89
90
  desc: 'Print only the matched parts.'
90
91
  def grep(default_pat = '[:precure_name:]', filename = nil)
91
- manager = CureGrepManager.new
92
- manager.source_input(filename)
93
- manager.pattern(default_pat.clone, options['extended-regexp'.to_sym])
92
+ logic = GrepLogic.new
93
+ logic.source_input(filename)
94
+ logic.pattern(default_pat.clone, options['extended-regexp'.to_sym])
94
95
  # Check the file discriptor to check the pipe exists or not.
95
- manager.option_colorize($stdout.isatty)
96
- manager.option_only(options['only-matching'.to_sym])
96
+ logic.option_colorize($stdout.isatty)
97
+ logic.option_only(options['only-matching'.to_sym])
97
98
  # Print matched lines.
98
- exit(manager.print_results)
99
+ exit(logic.print_results)
99
100
  end
100
101
 
101
102
  desc 'tr PATTERN REPLACE', 'Translate Precure related parameters.'
102
103
  def tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]')
103
- manager = CureTranslateManager.new
104
- manager.in = $stdin
105
- manager.translate_from_to(pat_from, pat_to)
106
- exit(manager.print_results)
104
+ logic = TranslateLogic.new
105
+ logic.in = $stdin
106
+ logic.translate_from_to(pat_from, pat_to)
107
+ exit(logic.print_results)
107
108
  end
108
109
 
109
110
  desc 'echo [OPTIONS] PATTERN', 'Print messages of Precure.'
@@ -123,30 +124,36 @@ module Cureutils
123
124
  type: :string,
124
125
  desc: 'Choose style of the transformation.'
125
126
  def echo
126
- manager = CureEchoManager.new
127
- manager.precure(options[:precure])
128
- manager.msg_attack(options[:attack])
129
- manager.nosleep(options[:quick])
130
- manager.style(options[:style])
131
- exit(manager.print_results)
127
+ logic = EchoLogic.new
128
+ logic.precure(options[:precure])
129
+ logic.msg_attack(options[:attack])
130
+ logic.nosleep(options[:quick])
131
+ logic.style(options[:style])
132
+ exit(logic.print_results)
132
133
  end
133
134
 
134
135
  desc 'date [OPTIONS] [+FORMAT]',
135
136
  'Display date, time and Precure related events.'
136
- option 'date', aliases: 'd'
137
+ option 'date', aliases: 'd',
138
+ type: :string,
139
+ desc: '-d STRING: Display time described by STRING.'
140
+ option 'file', aliases: 'f',
141
+ type: :string,
142
+ desc: '-f DATEFILE: Load each line of DATEFILE as STRING of -d option.'
137
143
  # Original date command's default is '+%a %b %e %H:%M:%S %Z %Y @P'
138
144
  # However, I would like to adopt this setting.
139
145
  def date(fmt = '+%F %H:%M:%S @P')
140
- manager = CureDateManager.new
141
- manager.datetime(options[:date])
142
- manager.format = fmt
143
- exit(manager.print_results)
146
+ logic = DateLogic.new
147
+ logic.opt_date(options[:date])
148
+ logic.opt_file(options[:file])
149
+ logic.format = fmt
150
+ exit(logic.print_results)
144
151
  end
145
152
 
146
153
  desc 'janken', %q(Let's play "Pikarin Janken" !)
147
154
  def janken
148
- manager = CureJankenManager.new
149
- exit(manager.janken.to_i)
155
+ logic = JankenLogic.new
156
+ exit(logic.janken.to_i)
150
157
  end
151
158
  end
152
159
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
2
3
  #
3
4
  # Class includes common methos which are refered from multiple commands.
@@ -18,7 +19,7 @@ class Common
18
19
  end
19
20
 
20
21
  def cure_list(sym)
21
- list = Precure.all_stars.map(&sym)
22
+ list = Precure.all_girls.map(&sym)
22
23
  list << Cure.echo[sym]
23
24
  # Regulate cure princes human name
24
25
  list.map do |str|
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+
4
+ #
5
+ # Base class of logic class
6
+ #
7
+ class BaseLogic
8
+ def initialize
9
+ @in = $stdin
10
+ @out = $stdout
11
+ @err = $stderr
12
+ end
13
+
14
+ def source_output(source = $stdout)
15
+ @out = source
16
+ end
17
+
18
+ def source_input(source = $stdin)
19
+ @in = source
20
+ if source.nil? || source =~ /^-$/
21
+ # If the file name is "-", use STDIN.
22
+ @in = $stdin
23
+ else
24
+ file(source)
25
+ end
26
+ end
27
+
28
+ def source_err(source = $stderr)
29
+ @err = source
30
+ end
31
+
32
+ private
33
+
34
+ def file(filename)
35
+ @in = File.open(filename)
36
+ rescue SystemCallError => e
37
+ @err.puts e.message.to_s
38
+ # TODO: Define error codes as enum.
39
+ exit(2)
40
+ rescue IOError => e
41
+ @err.puts e.message.to_s
42
+ exit(2)
43
+ end
44
+ end
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+ require 'cureutils/logic/base_logic'
4
+ require 'date'
5
+
6
+ #
7
+ # Date class supports the precure format
8
+ #
9
+ class DateLogic < BaseLogic
10
+ def initialize
11
+ super
12
+ hashize_cure_date
13
+ hashize_movie_date
14
+ @in = []
15
+ @in << nil
16
+ @opt_date = false
17
+ @opt_file = false
18
+ @format = '+%F %H:%M:%S @P'
19
+ end
20
+
21
+ def opt_date(given_datetime)
22
+ return if given_datetime.nil?
23
+ @opt_date = true
24
+ @in = []
25
+ @in << given_datetime
26
+ end
27
+
28
+ def opt_file(filename)
29
+ return if filename.nil?
30
+ @opt_file = true
31
+ source_input(filename)
32
+ end
33
+
34
+ attr_writer :format
35
+
36
+ def print_results
37
+ return 1 unless check_opts
38
+ @in.each do |line|
39
+ given_date = line ? natural_lang2time(line) : Time.now
40
+ updated_fmt = update_fmt(given_date, @format) if given_date
41
+ @out.puts given_date.strftime(updated_fmt) if updated_fmt
42
+ end
43
+ 0
44
+ end
45
+
46
+ private
47
+
48
+ def check_opts
49
+ # Either option must be true, but both must NOT be same.
50
+ return true unless @opt_date && @opt_file
51
+ @err.puts <<-EOS
52
+ cure date: the options to specify dates for printing are mutually exclusive.
53
+ EOS
54
+ false
55
+ end
56
+
57
+ def validate_date_str(str)
58
+ Date.parse(str)
59
+ rescue ArgumentError => e
60
+ @err.puts "cure date: #{e.message} '#{str.chomp}'"
61
+ return false
62
+ end
63
+
64
+ def natural_lang2time(time_str)
65
+ updated_fmt = time_str.dup
66
+ updated_fmt.gsub!(/yesterday/, '1 day ago')
67
+ updated_fmt.gsub!(/tomorrow/, '-1 day ago')
68
+ units = 'second|minute|hour|day|week|month|year'
69
+ regulated_format = /(-?[0-9]+) *(#{units})s? *(ago)?/
70
+ if updated_fmt =~ regulated_format
71
+ diff_value = Regexp.last_match(1).to_i
72
+ unit = Regexp.last_match(2).to_sym
73
+ minus_flg = Regexp.last_match(3)
74
+ return Time.now + diff_value.send(unit) if minus_flg.nil?
75
+ return Time.now - diff_value.send(unit)
76
+ elsif validate_date_str(updated_fmt)
77
+ # Format like "yyyy-mm-dd", "yyyy/mm/dd" and "yyyymmdd"
78
+ return Time.parse(updated_fmt)
79
+ end
80
+ false
81
+ end
82
+
83
+ def update_fmt(datetime, fmt)
84
+ # Find precure related events
85
+ date4check_event = time2date(datetime)
86
+ found_event = events(date4check_event)
87
+ checked_fmt = fmt
88
+ if fmt =~ /^\+(.*)$/
89
+ checked_fmt = Regexp.last_match(1)
90
+ else
91
+ @err.puts "cure date: invalid date format '#{fmt}'"
92
+ exit 1
93
+ end
94
+ # Find precure related events
95
+ checked_fmt.gsub(/@P/, found_event)
96
+ end
97
+
98
+ def events(date)
99
+ event_list = [birth_date?(date),
100
+ created_date?(date),
101
+ movie_date?(date),
102
+ series_between(date)].compact
103
+ event_list.flatten.join('/')
104
+ end
105
+
106
+ def time2date(time_obj)
107
+ Date.parse(time_obj.strftime('%Y-%m-%d'))
108
+ end
109
+
110
+ def birth_date?(date)
111
+ date_str = date.strftime('%-m/%-d')
112
+ result = @birth_date[date_str.to_sym]
113
+ return if result.nil?
114
+ result.map { |v| "#{v[:human_name]}(#{v[:precure_name]})誕生日" }
115
+ end
116
+
117
+ def created_date?(date)
118
+ date_str = date.strftime('%Y-%m-%d')
119
+ result = @created_date[date_str.to_sym]
120
+ return if result.nil?
121
+ result.map { |v| v[:precure_name] + '登場日' }
122
+ end
123
+
124
+ def movie_date?(date)
125
+ date_str = date.strftime('%Y-%m-%d')
126
+ result = @movie_started_date[date_str.to_sym]
127
+ # format
128
+ "#{result[:title]}映画公開日" unless result.nil?
129
+ end
130
+
131
+ def series_between(date)
132
+ event_name = nil
133
+ Rubicure::Series.config.each do |_k, v|
134
+ if v[:started_date] == date
135
+ event_name = "#{v[:title]}初放映"
136
+ break
137
+ end
138
+ if v[:ended_date] == date
139
+ event_name = "#{v[:title]}最終回"
140
+ break
141
+ end
142
+ # Nobody expects the future. Precure series may be abolished today.
143
+ v[:ended_date] = Date.today + 1 if v[:ended_date].nil?
144
+ if v[:started_date] < date && date < v[:ended_date]
145
+ event_name = "#{v[:title]}放映期間"
146
+ break
147
+ end
148
+ end
149
+ event_name
150
+ end
151
+
152
+ def hashize_cure_date
153
+ @birth_date = {}
154
+ @created_date = {}
155
+ Precure.all_girls.each do |precure|
156
+ # Create birthday table
157
+ birthday_key = precure.birthday.to_s.to_sym
158
+ @birth_date =
159
+ create_array_on_hash(@birth_date, birthday_key, precure)
160
+ # Create table for the first appeared date .
161
+ created_date_key = precure.created_date.strftime('%Y-%m-%d').to_sym
162
+ @created_date =
163
+ create_array_on_hash(@created_date, created_date_key, precure)
164
+ end
165
+ end
166
+
167
+ def create_array_on_hash(arr_hash, key, value)
168
+ arr_hash[key] = [] unless arr_hash.key?(key)
169
+ arr_hash[key] << value
170
+ arr_hash
171
+ end
172
+
173
+ def hashize_movie_date
174
+ @movie_started_date = {}
175
+ Rubicure::Movie.config.map do |_k, v|
176
+ next if v[:started_date].nil?
177
+ @movie_started_date[v[:started_date].strftime('%Y-%m-%d').to_sym] = v
178
+ end
179
+ end
180
+ end
@@ -1,33 +1,21 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
3
+ require 'cureutils/logic/base_logic'
2
4
 
3
5
  # Singleton class for cure echo
4
- class CureEchoManager
6
+ class EchoLogic < BaseLogic
5
7
  module EchoMode
6
8
  TRANSFORM = 1
7
9
  ATTACK = 2
8
10
  end
9
11
 
10
12
  def initialize
11
- @in = $stdin
12
- @out = $stdout
13
- @err = $stderr
13
+ super
14
14
  @cure_name = 'echo'
15
15
  @message_mode = EchoMode::TRANSFORM
16
16
  @style_priority = []
17
17
  end
18
18
 
19
- def source_output(source = $stdout)
20
- @out = source
21
- end
22
-
23
- def source_input(source = $stdin)
24
- @in = source
25
- end
26
-
27
- def source_err(source = $stderr)
28
- @err = source
29
- end
30
-
31
19
  def precure(cure_name = false)
32
20
  @cure_name = cure_name || 'echo'
33
21
  end
@@ -1,18 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
3
+ require 'cureutils/logic/base_logic'
2
4
  require 'colorize'
3
5
 
4
6
  # Singleton class for cure grep
5
7
  # Managing the method for matching and printing.
6
- class CureGrepManager
8
+ class GrepLogic < BaseLogic
7
9
  module ColorMode
8
10
  NONE = :to_s
9
11
  RED = :red
10
12
  end
11
13
 
12
14
  def initialize
13
- @in = $stdin
14
- @out = $stdout
15
- @err = $stderr
15
+ super
16
16
  @match_method = 'match'
17
17
  end
18
18
 
@@ -25,21 +25,6 @@ class CureGrepManager
25
25
  @str_color = (colorize ? ColorMode::RED : ColorMode::NONE)
26
26
  end
27
27
 
28
- def source_output(source = $stdout)
29
- @out = source
30
- end
31
-
32
- def source_input(source = nil)
33
- if source.nil? || source.empty?
34
- @in = $stdin
35
- elsif source =~ /^-$/
36
- # If the file name is "-", use STDIN.
37
- @in = $stdin
38
- else
39
- file(source)
40
- end
41
- end
42
-
43
28
  def pattern(pat, is_exregex = false)
44
29
  if is_exregex
45
30
  @pattern = /#{pat}/
@@ -62,14 +47,4 @@ class CureGrepManager
62
47
  end
63
48
  exit_status
64
49
  end
65
-
66
- private
67
-
68
- def file(filename)
69
- @in = File.open(filename)
70
- rescue SystemCallError => e
71
- puts %(class=[#{e.class}] message=[#{e.message}])
72
- rescue IOError => e
73
- puts %(class=[#{e.class}] message=[#{e.message}])
74
- end
75
50
  end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
3
+ require 'cureutils/logic/base_logic'
4
+
2
5
  #
3
6
  # Class of Pikarin Janken
4
7
  #
5
- class CureJankenManager
8
+ class JankenLogic < BaseLogic
6
9
  def initialize
10
+ super
7
11
  # Set the sleep time 0
8
12
  Rubicure::Girl.sleep_sec = 0
9
13
  # 0: win, 1: lose, 2: aiko
@@ -15,15 +19,10 @@ class CureJankenManager
15
19
  @te_idx = %w(グー チョキ パー グッチョッパー)
16
20
  @te_hash = Hash[[@te_idx, (0..3).map(&:to_s)].transpose]
17
21
  @buf = []
18
- @out = $stdout
19
22
  end
20
23
 
21
24
  attr_writer :io
22
25
 
23
- def source_output(output = $stdout)
24
- @out = output
25
- end
26
-
27
26
  def puts(input)
28
27
  @buf << input
29
28
  end
@@ -43,7 +42,7 @@ class CureJankenManager
43
42
  end
44
43
 
45
44
  def input_te
46
- @out.print("1...グー, 2...チョキ, 3...パー : ")
45
+ @out.print('1...グー, 2...チョキ, 3...パー : ')
47
46
  # TODO: Check input and raise the error.
48
47
  player_te = $stdin.gets
49
48
  player_te.to_i - 1
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
3
+ require 'cureutils/logic/base_logic'
4
+
2
5
  #
3
6
  # Class for managing cure tr (translate).
4
7
  #
5
- class CureTranslateManager
8
+ class TranslateLogic < BaseLogic
6
9
  def initialize
10
+ super
7
11
  @translate_from = :human_name
8
12
  @translate_to = :precure_name
9
- @out = $stdout
10
- @in = $stdin
11
13
  end
12
14
 
13
- attr_writer :out, :in
15
+ attr_writer :in
14
16
 
15
17
  def translate_from_to(from, to)
16
18
  @translate_from = pregex2str(from).to_sym
@@ -37,7 +39,7 @@ class CureTranslateManager
37
39
  line.scan(/#{cure_pattern}/).each do |pat|
38
40
  updated_line.gsub!(/#{pat[0]}/, table[pat[0]])
39
41
  end
40
- puts updated_line
42
+ @out.puts updated_line
41
43
  end
42
44
  0
43
45
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  module Cureutils
2
3
  class Version
3
- MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ PATCH = 0
6
7
  PRE = nil
7
8
 
8
9
  class << self
data/zsh-completion/_cure CHANGED
@@ -17,7 +17,7 @@ subcommands=(
17
17
  "transform: Replace human_name to precure_name"
18
18
  )
19
19
 
20
- # cure precures | cure tr [:precure_name:] [:girl_name:] | grep '[[:alnum:]]' | sort | uniq | sed 's/^cure_//'
20
+ # bundle exec cure precures -m |bundle exec cure tr [:precure_name:] [:girl_name:] | grep '[[:alnum:]]' | sort | uniq
21
21
  precure_girl_names=(
22
22
  'cure_ace'
23
23
  'cure_aqua'
@@ -27,6 +27,8 @@ precure_girl_names=(
27
27
  'cure_black'
28
28
  'cure_bloom'
29
29
  'cure_blossom'
30
+ 'cure_chocolat'
31
+ 'cure_custard'
30
32
  'cure_diamond'
31
33
  'cure_dream'
32
34
  'cure_echo'
@@ -34,11 +36,13 @@ precure_girl_names=(
34
36
  'cure_felice'
35
37
  'cure_flora'
36
38
  'cure_fortune'
39
+ 'cure_gelato'
37
40
  'cure_happy'
38
41
  'cure_heart'
39
42
  'cure_honey'
40
43
  'cure_lemonade'
41
44
  'cure_lovely'
45
+ 'cure_macaroon'
42
46
  'cure_magical'
43
47
  'cure_march'
44
48
  'cure_marine'
@@ -61,6 +65,7 @@ precure_girl_names=(
61
65
  'cure_sunshine'
62
66
  'cure_sword'
63
67
  'cure_twinkle'
68
+ 'cure_whip'
64
69
  'cure_white'
65
70
  'milky_rose'
66
71
  'shiny_luminous'
@@ -115,7 +120,7 @@ function _cure-echo () {
115
120
  function _cure-date () {
116
121
  local -a args
117
122
  args=(
118
- '-d: cure date -d STRING: display time described by STRING'
123
+ '-d: cure date -d STRING: Display time described by STRING.'
119
124
  '+%Y/%m/%d_%H\:%M\:%S_@P: Example date string 1.'
120
125
  '+%Y/%m/%d_@P: Example date string 2.'
121
126
  )
@@ -139,7 +144,7 @@ function _cure-precures () {
139
144
  function _cure-girls () {
140
145
  local -a args
141
146
  if (( CURRENT>=3 )) ; then
142
- echo $words | grep -w -- '-v' 1> /dev/null || args=($args "-v:Include particular girl's full name.")
147
+ echo $words | grep -w -- '-f' 1> /dev/null || args=($args "-f:Show girl's full name if it exists.")
143
148
  echo $words | grep -w -- '-m' 1> /dev/null || args=($args '-m:Include who have only appeared in the movies.')
144
149
  _describe -t args 'args' args
145
150
  fi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cureutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamada, Yasuhiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-16 00:00:00.000000000 Z
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0.4'
81
+ version: 1.0.0
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0.4'
88
+ version: 1.0.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: colorize
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -104,16 +104,16 @@ dependencies:
104
104
  name: activesupport
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 4.2.6
109
+ version: 5.0.0
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 4.2.6
116
+ version: 5.0.0
117
117
  description: Useful command line tool for Japanese battle heroine Pretty Cure (Precure).
118
118
  email:
119
119
  - greengregson@gmail.com
@@ -133,15 +133,17 @@ files:
133
133
  - bin/cure
134
134
  - cureutils.gemspec
135
135
  - cureutils.plugin.zsh
136
+ - img/cure_echo_demo.gif
136
137
  - img/cureutils_logo.png
137
138
  - lib/cureutils.rb
138
139
  - lib/cureutils/cli.rb
139
140
  - lib/cureutils/common.rb
140
- - lib/cureutils/cure_date_manager.rb
141
- - lib/cureutils/cure_echo_manager.rb
142
- - lib/cureutils/cure_grep_manager.rb
143
- - lib/cureutils/cure_janken_manager.rb
144
- - lib/cureutils/cure_translate_manager.rb
141
+ - lib/cureutils/logic/base_logic.rb
142
+ - lib/cureutils/logic/date_logic.rb
143
+ - lib/cureutils/logic/echo_logic.rb
144
+ - lib/cureutils/logic/grep_logic.rb
145
+ - lib/cureutils/logic/janken_logic.rb
146
+ - lib/cureutils/logic/translate_logic.rb
145
147
  - lib/cureutils/version.rb
146
148
  - zsh-completion/_cure
147
149
  homepage: https://github.com/greymd/cureutils
@@ -156,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
158
  requirements:
157
159
  - - ">="
158
160
  - !ruby/object:Gem::Version
159
- version: 2.0.0
161
+ version: 2.2.2
160
162
  required_rubygems_version: !ruby/object:Gem::Requirement
161
163
  requirements:
162
164
  - - ">="
@@ -164,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  requirements: []
166
168
  rubyforge_project:
167
- rubygems_version: 2.4.5
169
+ rubygems_version: 2.5.1
168
170
  signing_key:
169
171
  specification_version: 4
170
172
  summary: Useful commands for battle heroine Pretty Cure (Precure).
@@ -1,137 +0,0 @@
1
- # coding: utf-8
2
- require 'date'
3
-
4
- #
5
- # Date class supports the precure format
6
- #
7
- class CureDateManager
8
- def initialize
9
- hashize_cure_date unless @birth_date || @created_date
10
- hashize_movie_date unless @movie_started_date
11
- @datetime = Time.now
12
- @format = '+%F %H:%M:%S @P'
13
- @out = $stdout
14
- end
15
-
16
- def source_output(output = $stdout)
17
- @out = output
18
- end
19
-
20
- def datetime(datetime_str)
21
- @datetime = datetime_str ? natural_lang2time(datetime_str) : Time.now
22
- end
23
-
24
- attr_writer :format
25
-
26
- def print_results
27
- updated_fmt = update_fmt(@datetime, @format)
28
- @out.puts @datetime.strftime(updated_fmt)
29
- 0
30
- end
31
-
32
- private
33
-
34
- def natural_lang2time(time_str)
35
- updated_fmt = time_str.dup
36
- updated_fmt.gsub!(/yesterday/, '1 day ago')
37
- updated_fmt.gsub!(/tomorrow/, '-1 day ago')
38
- units = 'second|minute|hour|day|week|month|year'
39
- regulated_format = /(-?[0-9]+) *(#{units})s? *(ago)?/
40
- if updated_fmt =~ regulated_format
41
- diff_value = Regexp.last_match(1).to_i
42
- unit = Regexp.last_match(2).to_sym
43
- minus_flg = Regexp.last_match(3)
44
- if minus_flg.nil?
45
- Time.now + diff_value.send(unit)
46
- else
47
- Time.now - diff_value.send(unit)
48
- end
49
- else
50
- Time.parse(updated_fmt)
51
- end
52
- end
53
-
54
- def update_fmt(datetime, fmt)
55
- # Find precure related events
56
- date4check_event = time2date(datetime)
57
- found_event = events(date4check_event)
58
- checked_fmt = fmt
59
- if fmt =~ /^\+(.*)$/
60
- checked_fmt = Regexp.last_match(1)
61
- else
62
- puts "cure date: invalid date format '#{fmt}'"
63
- exit 1
64
- end
65
- # Find precure related events
66
- checked_fmt.gsub(/@P/, found_event)
67
- end
68
-
69
- def events(date)
70
- event_list = [birth_date?(date),
71
- created_date?(date),
72
- movie_date?(date),
73
- series_between(date)].compact
74
- event_list.join('/')
75
- end
76
-
77
- def time2date(time_obj)
78
- Date.parse(time_obj.strftime('%Y-%m-%d'))
79
- end
80
-
81
- def birth_date?(date)
82
- date_str = date.strftime('%m/%d')
83
- result = @birth_date[date_str]
84
- # format
85
- result.nil? ? nil : "#{result[:human_name]}(#{result[:precure_name]})誕生日"
86
- end
87
-
88
- def created_date?(date)
89
- date_str = date.strftime('%m/%d')
90
- result = @created_date[date_str]
91
- # format
92
- result.nil? ? nil : "#{result[:precure_name]}初登場日"
93
- end
94
-
95
- def movie_date?(date)
96
- result = @created_date[date]
97
- # format
98
- result.nil? ? nil : "#{result[:title]}映画公開日"
99
- end
100
-
101
- def series_between(date)
102
- event_name = nil
103
- Rubicure::Series.config.each do |_k, v|
104
- if v[:started_date] == date
105
- event_name = "#{v[:title]}初放映"
106
- break
107
- end
108
- if v[:ended_date] == date
109
- event_name = "#{v[:title]}最終回"
110
- break
111
- end
112
- # Nobody expects the future. Precure series may be abolished today.
113
- v[:ended_date] = Date.today + 1 if v[:ended_date].nil?
114
- if v[:started_date] < date && date < v[:ended_date]
115
- event_name = "#{v[:title]}放映期間"
116
- break
117
- end
118
- end
119
- event_name
120
- end
121
-
122
- def hashize_cure_date
123
- @birth_date = {}
124
- @created_date = {}
125
- Rubicure::Girl.config.map do |_k, v|
126
- v[:birthday].nil? || @birth_date[v[:birthday]] = v
127
- v[:created_date].nil? || @created_date[v[:created_date]] = v
128
- end
129
- end
130
-
131
- def hashize_movie_date
132
- @movie_started_date = {}
133
- Rubicure::Movie.config.map do |_k, v|
134
- v[:started_date].nil? || @movie_started_date[v[:started_date]] = v
135
- end
136
- end
137
- end