Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/migemo/core_ext/string.rb
Constant Summary collapse
- HANZEN_TAB =
{ " " => " ", "!" => "!", '"' => "”", "#" => "#", "\$" => "$", "%" => "%", "&" => "&", "'" => "’", "(" => "(", ")" => ")", "*" => "*", "+" => "+", "," => ",", "-" => "−", "." => ".", "/" => "/", "0" => "0", "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", ":" => ":", ";" => ";", "<" => "<", "=" => "=", ">" => ">", "?" => "?", '@' => "@", "A" => "A", "B" => "B", "C" => "C", "D" => "D", "E" => "E", "F" => "F", "G" => "G", "H" => "H", "I" => "I", "J" => "J", "K" => "K", "L" => "L", "M" => "M", "N" => "N", "O" => "O", "P" => "P", "Q" => "Q", "R" => "R", "S" => "S", "T" => "T", "U" => "U", "V" => "V", "W" => "W", "X" => "X", "Y" => "Y", "Z" => "Z", "[" => "[", "\\" => "\", "]" => "]", "^" => "^", "_" => "_", "`" => "‘", "a" => "a", "b" => "b", "c" => "c", "d" => "d", "e" => "e", "f" => "f", "g" => "g", "h" => "h", "i" => "i", "j" => "j", "k" => "k", "l" => "l", "m" => "m", "n" => "n", "o" => "o", "p" => "p", "q" => "q", "r" => "r", "s" => "s", "t" => "t", "u" => "u", "v" => "v", "w" => "w", "x" => "x", "y" => "y", "z" => "z", "{" => "{", "|" => "|", "}" => "}", "~" => "‾"}
- HANZEN_RE =
‘
Regexp.new(HANZEN_TAB.keys.sort.map {|x| Regexp.quote(x) }.join('|'))
Instance Method Summary collapse
- #first ⇒ Object
- #last ⇒ Object
- #prefix_match(string) ⇒ Object
- #rest ⇒ Object
- #to_fullwidth ⇒ Object
-
#to_katakana ⇒ Object
Hiragana to Katakana.
Instance Method Details
#first ⇒ Object
8 9 10 11 |
# File 'lib/migemo/core_ext/string.rb', line 8 def first /^(\\.|.)/ =~ self $1 end |
#last ⇒ Object
13 14 15 16 |
# File 'lib/migemo/core_ext/string.rb', line 13 def last /(\\.|.)$/ =~ self $1 end |
#prefix_match(string) ⇒ Object
57 58 59 |
# File 'lib/migemo/core_ext/string.rb', line 57 def prefix_match (string) self[0, string.length] <=> string end |
#rest ⇒ Object
18 19 20 21 |
# File 'lib/migemo/core_ext/string.rb', line 18 def rest /^(\\.|.)(.*)/ =~ self $2 end |
#to_fullwidth ⇒ Object
53 54 55 |
# File 'lib/migemo/core_ext/string.rb', line 53 def to_fullwidth self.gsub(HANZEN_RE) {|s| HANZEN_TAB[s]} end |
#to_katakana ⇒ Object
Hiragana to Katakana
4 5 6 |
# File 'lib/migemo/core_ext/string.rb', line 4 def to_katakana self.gsub(/う゛/, 'ヴ').tr('ぁ-ん', 'ァ-ン') end |