Module: FeCoreExt::CoreExt::String
- Included in:
- String
- Defined in:
- lib/fe_core_ext/core_ext/string.rb
Instance Method Summary collapse
- #alphanumeric_zen_to_han ⇒ Object
- #eucjp_encodable ⇒ Object
- #integer? ⇒ Boolean
- #kana_upcase ⇒ Object
- #match?(str) ⇒ Boolean
- #not_number? ⇒ Boolean
- #sjis_encodable ⇒ Object
-
#strong_strip ⇒ Object
remove also no break space and other space like characters.
- #to_date_in_ja ⇒ Object
- #to_date_in_ja_heisei ⇒ Object
- #to_date_in_ja_seireki ⇒ Object
- #to_decimal ⇒ Object
- #to_decimal_new ⇒ Object
- #to_float ⇒ Object
- #to_han_kana ⇒ Object
- #to_integer ⇒ Object
- #to_katakana ⇒ Object
- #to_pathname ⇒ Object
- #to_zen_kana ⇒ Object
- #valid_number? ⇒ Boolean
- #valid_sec_code? ⇒ Boolean
-
#zen_to_han ⇒ Object
deprecated.
Instance Method Details
#alphanumeric_zen_to_han ⇒ Object
58 59 60 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 58 def alphanumeric_zen_to_han tr("0-9A-Za-z &・.-()", '0-9A-Za-z &・.\-()') end |
#eucjp_encodable ⇒ Object
106 107 108 109 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 106 def eucjp_encodable tr("\uFF5E\uFF0D\uFFE0\uFFE1\uFFE2\u2015\u2225", "\u301C\u2212\u00A2\u00A3\u00AC\u2014\u2016") end |
#integer? ⇒ Boolean
17 18 19 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 17 def integer? self.to_integer.to_s == self.delete(",") end |
#kana_upcase ⇒ Object
70 71 72 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 70 def kana_upcase tr("ァィゥェォヵヶッャュョヮ", "アイウエオカケツヤユヨワ") end |
#match?(str) ⇒ Boolean
66 67 68 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 66 def match?(str) /#{str}/ === self end |
#not_number? ⇒ Boolean
45 46 47 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 45 def not_number? to_i == 0 && match("0").nil? end |
#sjis_encodable ⇒ Object
101 102 103 104 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 101 def sjis_encodable tr("\u301C\u2212\u00A2\u00A3\u00AC\u2014\u2016", "\uFF5E\uFF0D\uFFE0\uFFE1\uFFE2\u2015\u2225") end |
#strong_strip ⇒ Object
remove also no break space and other space like characters.
97 98 99 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 97 def strong_strip reverse.gsub(/^\p{Zs}+|^\p{Cf}+/, "").reverse.gsub(/^\p{Zs}+|^\p{Cf}+/, "") end |
#to_date_in_ja ⇒ Object
84 85 86 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 84 def to_date_in_ja to_date_in_ja_seireki || to_date_in_ja_heisei end |
#to_date_in_ja_heisei ⇒ Object
92 93 94 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 92 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_seireki ⇒ Object
88 89 90 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 88 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_decimal ⇒ Object
21 22 23 24 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 21 def to_decimal return unless valid_number? delete(",").to_d end |
#to_decimal_new ⇒ Object
26 27 28 29 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 26 def to_decimal_new return unless valid_number? delete(",").to_d end |
#to_float ⇒ Object
31 32 33 34 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 31 def to_float return unless valid_number? delete(",").to_f end |
#to_han_kana ⇒ Object
74 75 76 77 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 74 def to_han_kana return if self.nil? NKF.nkf("-wxZ4", self) end |
#to_integer ⇒ Object
12 13 14 15 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 12 def to_integer return unless valid_number? delete(",").to_i end |
#to_katakana ⇒ Object
62 63 64 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 62 def to_katakana tr("ぁ-ん", "ァ-ン") end |
#to_pathname ⇒ Object
41 42 43 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 41 def to_pathname Pathname(self) end |
#to_zen_kana ⇒ Object
79 80 81 82 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 79 def to_zen_kana return if self.nil? NKF.nkf("-wX", self) end |
#valid_number? ⇒ Boolean
49 50 51 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 49 def valid_number? match?(/^-?([0-9][\d,.]*)$/) end |
#valid_sec_code? ⇒ Boolean
36 37 38 39 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 36 def valid_sec_code? valid_chars = "[0-9ACDFGHJKLMNPRSTUWXY]" match?(/^\d#{valid_chars}\d#{valid_chars}$/) end |
#zen_to_han ⇒ Object
deprecated
54 55 56 |
# File 'lib/fe_core_ext/core_ext/string.rb', line 54 def zen_to_han tr("0-9A-Za-z &・-()", '0-9A-Za-z &・\-()') end |