Module: PositiveStringSupport::StringExt
- Defined in:
- lib/positive_string_support/string_ext.rb
Overview
文字列 String への追加機能をまとめたモジュール
Instance Method Summary collapse
- #convert_comma_between_number_to_dot ⇒ Object
- #convert_meta_character_in_regexp ⇒ Object
-
#convert_slash_to_yen ⇒ Object
ファイル名を処理するメソッド.
-
#convert_yen_to_slash ⇒ Object
ファイル名を処理するメソッド.
- #hour_and_min? ⇒ Boolean (also: #is_hour_and_min?)
-
#is_binary_data? ⇒ Boolean
バイナリか否かを判定するメソッド.
-
#remove_dakuten ⇒ Object
ひらがなの濁点を除去するメソッド.
- #to_array_of_hour_and_min ⇒ Object
-
#to_strf(indent = 0) ⇒ String
インスタンスの情報を整形した文字列にして返すメソッド.
-
#valid_as_filename? ⇒ Boolean
ファイル名として適切か否かを判定する..
-
#zen_alphabet_to_han ⇒ String
全角アルファベットを半角アルファベットに変換するメソッド.
-
#zen_num_to_han ⇒ String
全角数字を半角数字に変換するメソッド.
Instance Method Details
#convert_comma_between_number_to_dot ⇒ Object
104 105 106 |
# File 'lib/positive_string_support/string_ext.rb', line 104 def convert_comma_between_number_to_dot gsub( /(?<=\d)、(?=\d)/ , "・" ) end |
#convert_meta_character_in_regexp ⇒ Object
100 101 102 |
# File 'lib/positive_string_support/string_ext.rb', line 100 def gsub( /(?=[\(\)\[\]\{\}\.\?\+\*\|\\])/ , "\\" ) end |
#convert_slash_to_yen ⇒ Object
ファイル名を処理するメソッド
91 92 93 |
# File 'lib/positive_string_support/string_ext.rb', line 91 def convert_slash_to_yen gsub( /\\/ , "\/" ) end |
#convert_yen_to_slash ⇒ Object
ファイル名を処理するメソッド
96 97 98 |
# File 'lib/positive_string_support/string_ext.rb', line 96 def convert_yen_to_slash gsub( /\// , "\\" ) end |
#hour_and_min? ⇒ Boolean Also known as: is_hour_and_min?
76 77 78 |
# File 'lib/positive_string_support/string_ext.rb', line 76 def hour_and_min? ::PositiveStringSupport::RegexpLibrary.string_of_hour_and_min =~ self end |
#is_binary_data? ⇒ Boolean
Note:
YAML でエラーが発生するのを防ぐために定義している。
バイナリか否かを判定するメソッド
27 28 29 |
# File 'lib/positive_string_support/string_ext.rb', line 27 def is_binary_data? false # 日本語がバイナリとみなされるのを防ぐ end |
#remove_dakuten ⇒ Object
ひらがなの濁点を除去するメソッド
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/positive_string_support/string_ext.rb', line 44 def remove_dakuten h = { "が" => "か" , "ぎ" => "き" , "ぐ" => "く" , "げ" => "け" , "ご" => "こ" , "ざ" => "さ" , "じ" => "し" , "ず" => "す" , "ぜ" => "せ" , "ぞ" => "そ" , "だ" => "た" , "ぢ" => "ち" , "づ" => "つ" , "で" => "て" , "ど" => "と" , "ば" => "は" , "び" => "ひ" , "ぶ" => "ふ" , "べ" => "へ" , "ぼ" => "ほ" , "ぱ" => "は" , "ぴ" => "ひ" , "ぷ" => "ふ" , "ぺ" => "へ" , "ぽ" => "ほ" } gsub( /[#{h.keys.join}]/ , h ) end |
#to_array_of_hour_and_min ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/positive_string_support/string_ext.rb', line 82 def to_array_of_hour_and_min if hour_and_min? split( /\:/ ).map( &:to_i ) else raise "Error: #{ self } (#{self.class.name}) is not valid." end end |
#to_strf(indent = 0) ⇒ String
Note:
配列やハッシュを変換するメソッドから呼び出される。
インスタンスの情報を整形した文字列にして返すメソッド
20 21 22 |
# File 'lib/positive_string_support/string_ext.rb', line 20 def to_strf( indent = 0 ) " " * indent + __to_s__ end |
#valid_as_filename? ⇒ Boolean
Note:
スペース (“ ”), “?”, “!” がファイル名に含まれていなければ true を返す.
ファイル名として適切か否かを判定する.
111 112 113 |
# File 'lib/positive_string_support/string_ext.rb', line 111 def valid_as_filename? /[ \?\!]/ !~ self end |
#zen_alphabet_to_han ⇒ String
全角アルファベットを半角アルファベットに変換するメソッド
39 40 41 |
# File 'lib/positive_string_support/string_ext.rb', line 39 def zen_alphabet_to_han ::Moji.zen_to_han( self , ::Moji::ZEN_ALPHA ) end |
#zen_num_to_han ⇒ String
全角数字を半角数字に変換するメソッド
33 34 35 |
# File 'lib/positive_string_support/string_ext.rb', line 33 def zen_num_to_han ::Moji.zen_to_han( self , ::Moji::ZEN_ALNUM ) end |