Class: Pokebell

Inherits:
Object
  • Object
show all
Defined in:
lib/pokebell.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Pokebell

Set message and make Pokebell codes.

Parameters:

  • str (String)

    message (contains Hiragana / Katakana / alphabet / digit)



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

#pokebellString (readonly) Also known as: code, num

Returns Pokebell codes (2-digit string).

Returns:

  • (String)

    Pokebell codes (2-digit string)



57
58
59
# File 'lib/pokebell.rb', line 57

def pokebell
  @pokebell
end

#strString (readonly) Also known as: to_s, text

Returns message (convert to Zenkaku charactors, especially from Hiragana to Katakana).

Returns:

  • (String)

    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.

Parameters:

  • num (String)

    Pokebell code (length must be even)

Returns:

Raises:

  • (ArgumentError)

    if param does not makes digit or its length is not even

Since:

  • 0.1.0



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

#inspectString

Returns:

  • (String)

Since:

  • 0.1.0



51
52
53
# File 'lib/pokebell.rb', line 51

def inspect
  %[#<str="#{@str}", pokebell="#{@pokebell}">]
end