Class: Pokebell
- Inherits:
-
Object
- Object
- Pokebell
- Defined in:
- lib/pokebell.rb
Instance Attribute Summary collapse
-
#pokebell ⇒ String
(also: #code, #num)
readonly
Pokebell codes (2-digit string).
-
#str ⇒ String
(also: #to_s, #text)
readonly
Message (convert to Zenkaku charactors, especially from Hiragana to Katakana).
Class Method Summary collapse
-
.number(num) ⇒ Pokebell
Set Pokebell code and make message string.
Instance Method Summary collapse
-
#initialize(str) ⇒ Pokebell
constructor
Set message and make Pokebell codes.
- #inspect ⇒ String
Constructor Details
#initialize(str) ⇒ Pokebell
Set message and make Pokebell codes.
12 13 14 15 |
# File 'lib/pokebell.rb', line 12 def initialize(str) @str = Moji.han_to_zen(hiragana2katakana(str.upcase.gsub(/\\/, ""))) @pokebell = pick_hankaku_code(zenkaku2hankaku(@str)).map{ |code| encode(code) }.join end |
Instance Attribute Details
#pokebell ⇒ String (readonly) Also known as: code, num
Returns Pokebell codes (2-digit string).
57 58 59 |
# File 'lib/pokebell.rb', line 57 def pokebell @pokebell end |
#str ⇒ String (readonly) Also known as: to_s, text
Returns message (convert to Zenkaku charactors, especially from Hiragana to Katakana).
63 64 65 |
# File 'lib/pokebell.rb', line 63 def str @str end |
Class Method Details
.number(num) ⇒ Pokebell
Set Pokebell code and make message string.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pokebell.rb', line 22 def self.number(num) num_str = num.to_s unless num_str == num_str[/(\d\d)+/] raise ArgumentError, "wrong digit length (must be even digits)" end two_digits_array = num_str.scan(/\d\d/) str_array_with_daku_handaku = make_str_array(two_digits_array) str_array = [] loop do follow_char = nil char = str_array_with_daku_handaku.shift break unless char follow_char_test = str_array_with_daku_handaku.first unless follow_char_test str_array << char break end if follow_char_test[/[゛゜]/] follow_char = str_array_with_daku_handaku.shift char = merge_daku_handaku(char, follow_char) end str_array << char end str = str_array.join Pokebell.new(str) end |
Instance Method Details
#inspect ⇒ String
51 52 53 |
# File 'lib/pokebell.rb', line 51 def inspect %[#<str="#{@str}", pokebell="#{@pokebell}">] end |