Class: String
Overview
:nodoc:
Instance Method Summary collapse
- #to_full_characters(alpha: true, number: true, symbol: false) ⇒ String
- #to_half_characters(alpha: true, number: true, symbol: false) ⇒ String
Instance Method Details
#to_full_characters(alpha: true, number: true, symbol: false) ⇒ String
Note:
반각 문자 -> 전각 문자
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/coaster/core_ext/string.rb', line 10 def to_full_characters(alpha: true, number: true, symbol: false) result = String.new return result if self.blank? (0...self.size).each do |i| half_ord = self[i].ord full_ord = half_ord + 0xfee0 char_ord = case half_ord when 0x20 then 0x3000 when ('0'.ord)..('9'.ord) then number ? full_ord : half_ord when ('A'.ord)..('Z'.ord) then alpha ? full_ord : half_ord when ('a'.ord)..('z'.ord) then alpha ? full_ord : half_ord when ('!'.ord)..('~'.ord) then symbol ? full_ord : half_ord else half_ord end result << char_ord.chr('UTF-8') end result end |
#to_half_characters(alpha: true, number: true, symbol: false) ⇒ String
Note:
전각 문자 -> 반각 문자
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/coaster/core_ext/string.rb', line 35 def to_half_characters(alpha: true, number: true, symbol: false) result = String.new return result if self.blank? (0...self.size).each do |i| full_ord = self[i].ord half_ord = full_ord - 0xfee0 char_ord = case full_ord when 0x3000 then 0x20 when ('0'.ord + 0xfee0)..('9'.ord + 0xfee0) then number ? half_ord : full_ord when ('A'.ord + 0xfee0)..('Z'.ord + 0xfee0) then alpha ? half_ord : full_ord when ('a'.ord + 0xfee0)..('z'.ord + 0xfee0) then alpha ? half_ord : full_ord when ('!'.ord + 0xfee0)..('~'.ord + 0xfee0) then symbol ? half_ord : full_ord else full_ord end result << char_ord.chr('UTF-8') end result end |