Sha256: 88c527b54f71edae57bd6661f5ff8ac7814d639a4ff2c4025c439ee37d4e767a

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

require 'bigdecimal'
require 'bigdecimal/util'
require 'pathname'

module FeCoreExt::CoreExt
end

module FeCoreExt::CoreExt::String
  def to_integer
    return if not_number?
    delete(',').to_i
  end

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

  def to_pathname
    Pathname(self)
  end

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

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

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

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

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

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

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

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

class String
  include FeCoreExt::CoreExt::String
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fe_core_ext-0.1.43 lib/fe_core_ext/core_ext/string.rb