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



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

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

#eucjp_encodableObject



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

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

#integer?Boolean

Returns:

  • (Boolean)


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

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

#kana_upcaseObject



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

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

#match?(str) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#not_number?Boolean

Returns:

  • (Boolean)


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

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

#sjis_encodableObject



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

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.



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

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

#to_date_in_jaObject



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

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



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

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

#to_decimal_newObject



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

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

#to_floatObject



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

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

#to_han_kanaObject



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

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_integer_newObject



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

def to_integer_new
  return unless valid_number?
  delete(',').to_i
end

#to_katakanaObject



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

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

#to_pathnameObject



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

def to_pathname
  Pathname(self)
end

#to_zen_kanaObject



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

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

#valid_number?Boolean

Returns:

  • (Boolean)


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

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

#zen_to_hanObject

deprecated



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

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