Sha256: 82ce3a38fb49f8eac5e2d0ffabd2e06b2e0a89e0b3854a1b426204b749bae616

Contents?: true

Size: 610 Bytes

Versions: 2

Compression:

Stored size: 610 Bytes

Contents

require 'mojiru/version'
require 'nkf'

module Mojiru
  UTF8_BOM = "\xEF\xBB\xBF"

  refine ::String do
    def zen_to_han
      NKF.nkf('-x -Z4 -W -w', self)
    end

    def han_to_zen
      NKF.nkf('-W -w', self).tr('0-9a-zA-Z', '0-9a-zA-Z')
    end

    def hiragana
      NKF.nkf('--hiragana -W -w', self)
    end

    def katakana
      NKF.nkf('--katakana -W -w', self)
    end

    def normalize_zen_han
      NKF.nkf('-m0Z1 -W -w', self)
    end

    def strip_blank
      gsub(/\A[[:blank:]]+|[[:blank:]]+\Z/, '')
    end

    def prepend_utf8_bom
      UTF8_BOM + self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mojiru-0.3.0 lib/mojiru.rb
mojiru-0.2.0 lib/mojiru.rb