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



57
58
59
# File 'lib/fe_core_ext/core_ext/string.rb', line 57

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

#eucjp_encodableObject



105
106
107
108
# File 'lib/fe_core_ext/core_ext/string.rb', line 105

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

#integer?Boolean

Returns:

  • (Boolean)


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

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

#kana_upcaseObject



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

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

#match?(str) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#not_number?Boolean

Returns:

  • (Boolean)


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

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

#sjis_encodableObject



100
101
102
103
# File 'lib/fe_core_ext/core_ext/string.rb', line 100

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.



96
97
98
# File 'lib/fe_core_ext/core_ext/string.rb', line 96

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

#to_date_in_jaObject



83
84
85
# File 'lib/fe_core_ext/core_ext/string.rb', line 83

def to_date_in_ja
  to_date_in_ja_seireki || to_date_in_ja_heisei
end

#to_date_in_ja_heiseiObject



91
92
93
# File 'lib/fe_core_ext/core_ext/string.rb', line 91

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



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

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_decimal_newObject



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

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

#to_floatObject



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

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

#to_han_kanaObject



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

def to_han_kana
  return if self.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



61
62
63
# File 'lib/fe_core_ext/core_ext/string.rb', line 61

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

#to_pathnameObject



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

def to_pathname
  Pathname(self)
end

#to_zen_kanaObject



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

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

#valid_number?Boolean

Returns:

  • (Boolean)


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

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

#valid_sec_code?Boolean

Returns:

  • (Boolean)


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

def valid_sec_code?
  valid_chars = "[0-9ACDFGHJKLMNPRSTUWXY]"
  match?(/^\d#{valid_chars}\d#{valid_chars}$/)
end

#zen_to_hanObject

deprecated



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

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