Module: FeCoreExt::CoreExt::String

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

Instance Method Summary collapse

Instance Method Details

#alphanumeric_zen_to_hanObject



47
48
49
# File 'lib/fe_core_ext/core_ext/string.rb', line 47

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

#integer?Boolean

Returns:

  • (Boolean)


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

def integer?
  to_integer.to_s == delete(",")
end

#kana_upcaseObject



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

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

#not_number?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/fe_core_ext/core_ext/string.rb', line 34

def not_number?
  to_i.zero? && match("0").nil?
end

#strong_stripObject

remove also no break space and other space like characters.



86
87
88
# File 'lib/fe_core_ext/core_ext/string.rb', line 86

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

#to_date_in_jaObject



73
74
75
# File 'lib/fe_core_ext/core_ext/string.rb', line 73

def to_date_in_ja
  to_date_in_ja_seireki || to_date_in_ja_heisei
end

#to_date_in_ja_heiseiObject



81
82
83
# File 'lib/fe_core_ext/core_ext/string.rb', line 81

def to_date_in_ja_heisei
  match(/平成(\d{2})年(\d{1,2})月(\d{1,2})日/) { Date.new($1.to_i + 1988, $2.to_i, $3.to_i) }
end

#to_date_in_ja_seirekiObject



77
78
79
# File 'lib/fe_core_ext/core_ext/string.rb', line 77

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

#to_decimalObject



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

def to_decimal
  return unless valid_number?
  delete(",").to_d
end

#to_floatObject



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

def to_float
  return unless valid_number?
  delete(",").to_f
end

#to_half_alphaObject



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

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

#to_han_kanaObject



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

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

#to_integerObject



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

def to_integer
  return unless valid_number?
  delete(",").to_i
end

#to_katakanaObject



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

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

#to_pathnameObject



30
31
32
# File 'lib/fe_core_ext/core_ext/string.rb', line 30

def to_pathname
  Pathname(self)
end

#to_zen_kanaObject



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

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

#valid_number?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/fe_core_ext/core_ext/string.rb', line 38

def valid_number?
  match?(/^-?([0-9][\d,.]*)$/)
end

#zen_to_hanObject

deprecated



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

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