pokeberu 0.1.3 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5eb9b7133595c7905f66170224c8e095f3925b68d810da1eee643d6949db1ebe
4
- data.tar.gz: ac4bddab585eab30297808b43fd354f52305e9fbc5be66ce460350c6e11839d1
3
+ metadata.gz: a5008bc20349e495bbbc583130a96fd500422b582fbd2a2ea0abe586d3e6e8bf
4
+ data.tar.gz: '09121533a1dc7c0a6c73534a6786276dea6e706b1c8c4a1ffa6bda06a4d7bf25'
5
5
  SHA512:
6
- metadata.gz: f8463cff066743d76c3b262e8acfb6056b0e3e7c7b2c96a8ca594c92f4a9ed7b2233f54813f7e0b851b0a52a9cc2266b7df97bc100580afe83a890bdb83c1197
7
- data.tar.gz: b345f713a02139317d43311da86e613375ebb32ceb7763ff863ef73b67e50cfcd5c174b1b87837e6880b758c4bed038bf099f02c05e9a6e4483da8c1528f6c46
6
+ metadata.gz: e93a8ee4630b4b06ec80d42ab423b6007722efef21fc55bc309a93109d799740f2794348f4144bdd814e140c3ac6ed599eab1e6bdb1493ea935809e18a9ef28f
7
+ data.tar.gz: 571a54c4d83b152d3345f8fb0cb3149988524014ff8543bbe09ff9c05210a5b8a94196d559ad85cf26d85ba95448c3aa3c9e19feeb0d6d22abe57ac56963bf38
@@ -0,0 +1,4 @@
1
+ ### 0.1.4 - 2019-11-01
2
+
3
+ * Show help with "h"
4
+ * Quit with "q" instead of "exit"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pokeberu (0.1.3)
4
+ pokeberu (0.1.4)
5
5
  mojinizer
6
6
 
7
7
  GEM
@@ -23,4 +23,4 @@ DEPENDENCIES
23
23
  rake (~> 10.0)
24
24
 
25
25
  BUNDLED WITH
26
- 1.17.2
26
+ 1.17.3
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- ```
24
+ ```ruby
25
25
  require 'pokeberu'
26
26
 
27
27
  converter = Pokeberu::Converter.new
@@ -29,17 +29,20 @@ converter.to_chars('1112324493')
29
29
  #=> アイシテル
30
30
  ```
31
31
 
32
- OR
32
+ Or
33
33
 
34
34
  ```
35
35
  $ pokeberu
36
- メッセージを入力してください (exitで終了): 1112324493
37
- ------------------
38
- | アイシテル |
39
- ------------------
36
+ メッセージを入力してください (h=help, q=quit): 1112324493
37
+ --------------------
38
+ | アイシテル |
39
+ --------------------
40
+
41
+ メッセージを入力してください (h=help, q=quit): q
42
+ --------------------
43
+ | BYE! |
44
+ --------------------
40
45
 
41
- メッセージを入力してください (exitで終了): exit
42
- Bye!
43
46
  ```
44
47
 
45
48
  ## Development
@@ -50,7 +53,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
50
53
 
51
54
  ## Contributing
52
55
 
53
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pokeberu. 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.
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JunichiIto/pokeberu. 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.
54
57
 
55
58
  ## License
56
59
 
@@ -12,12 +12,64 @@ module Pokeberu
12
12
  %w(ら り る れ ろ 1 2 3 4 5),
13
13
  %w(わ を ん ゛ ゜ 6 7 8 9 0),
14
14
  ]
15
+ HELP_COL_WIDTH = 4
16
+ H_BORDER = '-'
17
+ V_BORDER = '|'
15
18
 
16
19
  def to_chars(input)
17
- input.scan(/../).map { |row_col|
18
- row, col = row_col.chars.map(&:to_i)
19
- TABLE[row - 1][col - 1]
20
- }.join.katakana.zen_to_han
20
+ to_c = -> ((row, col)) { TABLE[row][col] }
21
+
22
+ input
23
+ .each_char
24
+ .map(&:to_i)
25
+ .map(&:pred)
26
+ .each_slice(2)
27
+ .map(&to_c)
28
+ .join
29
+ .katakana
30
+ .zen_to_han
31
+ end
32
+
33
+ def help
34
+ tr = []
35
+ TABLE.each.with_index(1) do |row, i|
36
+ tr << draw_full_border
37
+ tr << draw_char_cols(row)
38
+ tr << draw_num_cols(i)
39
+ end
40
+ tr << draw_full_border
41
+ tr.map(&method(:format_row)).join("\n")
42
+ end
43
+
44
+ private
45
+
46
+ def draw_char_cols(row)
47
+ row.map(&method(:format_char)).join(V_BORDER)
48
+ end
49
+
50
+ def format_char(c)
51
+ c.katakana.center(HELP_COL_WIDTH - 1)
52
+ end
53
+
54
+ def draw_num_cols(i)
55
+ i = 0 if i > 9
56
+ from = i * 10
57
+ to = from + 9
58
+ nums = (from..to).map(&method(:format_num))
59
+ nums.rotate(1).join(V_BORDER)
60
+ end
61
+
62
+ def format_num(n)
63
+ n.to_s.rjust(2, '0').center(HELP_COL_WIDTH)
64
+ end
65
+
66
+ def draw_full_border
67
+ col_count = TABLE[0].size
68
+ H_BORDER * (HELP_COL_WIDTH * col_count + col_count - 1)
69
+ end
70
+
71
+ def format_row(text)
72
+ [V_BORDER, text, V_BORDER].join
21
73
  end
22
74
  end
23
75
  end
@@ -3,11 +3,11 @@ module Pokeberu
3
3
  LENGTH = 16
4
4
 
5
5
  def decorate(text)
6
- lines = []
7
- lines << hr
8
- lines << "| #{text.ljust(LENGTH)} |"
9
- lines << hr
10
- lines.join("\n")
6
+ <<-TEXT
7
+ #{hr}
8
+ | #{text.ljust(LENGTH)} |
9
+ #{hr}
10
+ TEXT
11
11
  end
12
12
 
13
13
  private
@@ -13,15 +13,19 @@ module Pokeberu
13
13
 
14
14
  def run
15
15
  loop do
16
- print 'メッセージを入力してください (exitで終了): '
16
+ print 'メッセージを入力してください (h=help, q=quit): '
17
17
  input = gets.chomp
18
- if input == 'exit'
18
+ case input
19
+ when ?q
20
+ show_pokberu(BYE)
19
21
  break
22
+ when ?h
23
+ puts @converter.help
24
+ puts
20
25
  else
21
26
  show_pokberu(input)
22
27
  end
23
28
  end
24
- show_pokberu(BYE)
25
29
  end
26
30
 
27
31
  private
@@ -1,3 +1,3 @@
1
1
  module Pokeberu
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pokeberu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichi Ito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-12 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mojinizer
@@ -77,6 +77,7 @@ extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
79
79
  - ".travis.yml"
80
+ - CHANGELOG.md
80
81
  - CODE_OF_CONDUCT.md
81
82
  - Gemfile
82
83
  - Gemfile.lock