Sha256: fc717d0ed270b132928012a02efca13e2c90bb4cc0393358d4828f8cddbfc91f

Contents?: true

Size: 613 Bytes

Versions: 1

Compression:

Stored size: 613 Bytes

Contents

# frozen_string_literal: true

require 'nkf'

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

    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

1 entries across 1 versions & 1 rubygems

Version Path
mojiru-0.1.0 lib/mojiru/string.rb