Module: When::EncodingConversion
Overview
エンコーディングの変換
Instance Method Summary collapse
-
#+@ ⇒ Object
内部エンコーディング文字列化(単項).
-
#-@ ⇒ Object
外部エンコーディング文字列化(単項).
-
#to_external_encoding ⇒ Object
外部エンコーディング文字列化.
-
#to_internal_encoding ⇒ Object
内部エンコーディング文字列化.
Instance Method Details
#+@ ⇒ Object
内部エンコーディング文字列化(単項)
115 116 117 |
# File 'lib/when_exe/locales/encoding_conversion.rb', line 115 def +@ to_internal_encoding end |
#-@ ⇒ Object
外部エンコーディング文字列化(単項)
122 123 124 |
# File 'lib/when_exe/locales/encoding_conversion.rb', line 122 def -@ to_external_encoding end |
#to_external_encoding ⇒ Object
外部エンコーディング文字列化
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/when_exe/locales/encoding_conversion.rb', line 54 def to_external_encoding(source) default_external = Encoding.default_external case source when Locale ; source.to_external_encoding when String ; (source.encoding == default_external) ? source : source.encode(default_external) when Regexp ; (source.encoding == default_external) ? source : Regexp.new(source.to_s.encode(default_external)) when Array ; source.map {|e| to_external_encoding(e)} when Hash hash = {} source.each_pair do |key, value| hash[to_external_encoding(key)] = to_external_encoding(value) end hash else ; source.respond_to?(:to_external_encoding) ? source.to_external_encoding : source end end |
#to_internal_encoding ⇒ Object
内部エンコーディング文字列化
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/when_exe/locales/encoding_conversion.rb', line 25 def to_internal_encoding(source) default_internal = Encoding.default_internal||'UTF-8' case source when Locale ; source.to_internal_encoding when String ; (source.encoding == default_internal) ? source : source.encode(default_internal) when Regexp ; (source.encoding == default_internal) ? source : Regexp.new(source.to_s.encode(default_internal)) when Array ; source.map {|e| to_internal_encoding(e)} when Hash hash = {} source.each_pair do |key, value| hash[to_internal_encoding(key)] = to_internal_encoding(value) end hash else ; source.respond_to?(:to_internal_encoding) ? source.to_internal_encoding : source end end |