Module: FeCoreExt::CoreExt::String

Included in:
String
Defined in:
lib/fe_core_ext/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#eucjp_encodableObject



68
69
70
71
# File 'lib/fe_core_ext/core_ext/string.rb', line 68

def eucjp_encodable
  tr("\uFF5E\uFF0D\uFFE0\uFFE1\uFFE2\u2015\u2225",
     "\u301C\u2212\u00A2\u00A3\u00AC\u2014\u2016")
end

#kana_upcaseObject



40
41
42
# File 'lib/fe_core_ext/core_ext/string.rb', line 40

def kana_upcase
  tr('ァィゥェォヵヶッャュョヮ', 'アイウエオカケツヤユヨワ')
end

#match?(str) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/fe_core_ext/core_ext/string.rb', line 36

def match?(str)
  /#{str}/ === self
end

#not_number?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/fe_core_ext/core_ext/string.rb', line 24

def not_number?
  to_i == 0 && match('0').nil?
end

#sjis_encodableObject



63
64
65
66
# File 'lib/fe_core_ext/core_ext/string.rb', line 63

def sjis_encodable
  tr("\u301C\u2212\u00A2\u00A3\u00AC\u2014\u2016",
     "\uFF5E\uFF0D\uFFE0\uFFE1\uFFE2\u2015\u2225")
end

#strong_stripObject

remove also no break space and other space like characters.



59
60
61
# File 'lib/fe_core_ext/core_ext/string.rb', line 59

def strong_strip
  reverse.gsub(/^\p{Zs}+|^\p{Cf}+/, '').reverse.gsub(/^\p{Zs}+|^\p{Cf}+/, '')
end

#to_date_in_jaObject



54
55
56
# File 'lib/fe_core_ext/core_ext/string.rb', line 54

def to_date_in_ja
  match(/(\d{4})年(\d{1,2})月(\d{1,2})日/) {Date.new($1.to_i, $2.to_i, $3.to_i)}
end

#to_decimalObject



15
16
17
18
# File 'lib/fe_core_ext/core_ext/string.rb', line 15

def to_decimal
  return if not_number?
  delete(',').to_d
end

#to_han_kanaObject



44
45
46
47
# File 'lib/fe_core_ext/core_ext/string.rb', line 44

def to_han_kana
  return if self.nil?
  NKF.nkf('-wxZ4', self)
end

#to_integerObject



10
11
12
13
# File 'lib/fe_core_ext/core_ext/string.rb', line 10

def to_integer
  return if not_number?
  delete(',').to_i
end

#to_katakanaObject



32
33
34
# File 'lib/fe_core_ext/core_ext/string.rb', line 32

def to_katakana
  tr('ぁ-ん', 'ァ-ン')
end

#to_pathnameObject



20
21
22
# File 'lib/fe_core_ext/core_ext/string.rb', line 20

def to_pathname
  Pathname(self)
end

#to_zen_kanaObject



49
50
51
52
# File 'lib/fe_core_ext/core_ext/string.rb', line 49

def to_zen_kana
  return if self.nil?
  NKF.nkf('-wX', self)
end

#zen_to_hanObject



28
29
30
# File 'lib/fe_core_ext/core_ext/string.rb', line 28

def zen_to_han
  tr('0-9A-Za-z &・-()', '0-9A-Za-z &・\-()')
end