module PositiveStringSupport::StringExt

文字列 String への追加機能をまとめたモジュール

Public Instance Methods

convert_comma_between_number_to_dot() click to toggle source
# 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() click to toggle source
# File lib/positive_string_support/string_ext.rb, line 100
def convert_meta_character_in_regexp
  gsub( /(?=[\(\)\[\]\{\}\.\?\+\*\|\\])/ , "\\" )
end
convert_slash_to_yen() click to toggle source

ファイル名を処理するメソッド

# File lib/positive_string_support/string_ext.rb, line 91
def convert_slash_to_yen
  gsub( /\\/ , "\/" )
end
convert_yen_to_slash() click to toggle source

ファイル名を処理するメソッド

# File lib/positive_string_support/string_ext.rb, line 96
def convert_yen_to_slash
  gsub( /\// , "\\" )
end
hour_and_min?() click to toggle source
# File lib/positive_string_support/string_ext.rb, line 76
def hour_and_min?
   ::PositiveStringSupport::RegexpLibrary.string_of_hour_and_min =~ self
end
Also aliased as: is_hour_and_min?
is_binary_data?() click to toggle source

バイナリか否かを判定するメソッド @return [Boolean] @note YAML でエラーが発生するのを防ぐために定義している。

# File lib/positive_string_support/string_ext.rb, line 27
def is_binary_data?
  false # 日本語がバイナリとみなされるのを防ぐ
end
is_hour_and_min?()
Alias for: hour_and_min?
remove_dakuten() click to toggle source

ひらがなの濁点を除去するメソッド

# 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() click to toggle source
# 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 ) click to toggle source

インスタンスの情報を整形した文字列にして返すメソッド @param indent [Integer (>=0)] インデントの幅 @return [String] @note 配列やハッシュを変換するメソッドから呼び出される。

# File lib/positive_string_support/string_ext.rb, line 20
def to_strf( indent = 0 )
  " " * indent + __to_s__
end
valid_as_filename?() click to toggle source

ファイル名として適切か否かを判定する. @note スペース (“ ”), “?”, “!” がファイル名に含まれていなければ true を返す. @return [Boolean]

# File lib/positive_string_support/string_ext.rb, line 111
def valid_as_filename?
  /[ \?\!]/ !~ self
end
zen_alphabet_to_han() click to toggle source

全角アルファベットを半角アルファベットに変換するメソッド @return [String]

# 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() click to toggle source

全角数字を半角数字に変換するメソッド @return [String]

# File lib/positive_string_support/string_ext.rb, line 33
def zen_num_to_han
  ::Moji.zen_to_han( self , ::Moji::ZEN_ALNUM )
end