Sha256: b3c0009d76211718b73e62d8637f74f2dee0731779a150311bf6bd54e459c184

Contents?: true

Size: 923 Bytes

Versions: 107

Compression:

Stored size: 923 Bytes

Contents

require 'nkf'

module Daddy
  module Utils
    class StringUtils

      def self.to_hiragana(s)
        return s if is_empty(s)
        NKF::nkf('-Ww --hiragana', s)
      end
    
      def self.to_katakana(s)
        return s if is_empty(s)
        NKF::nkf('-Ww --katakana', s)
      end
    
      def self.to_zen(s)
        return s if is_empty(s)
        NKF::nkf('-WwXm0', s)
      end
    
      def self.to_han(s)
        return s if is_empty(s)
        NKF::nkf('-Wwxm0Z0', s)
      end
    
      def self.current_time(now = nil)
        now = Time.now unless now
        now.instance_eval { '%s%03d' % [strftime('%Y%m%d%H%M%S'), (usec / 1000.0).round] }
      end
    
      def self.rand(length = 8)
        chars = ("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a
        ret = []
        length.times do |i|
          ret[i] = chars[rand(chars.size)]
        end
        ret.join
      end

    end
  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
daddy-0.5.3 lib/daddy/utils/string_utils.rb
daddy-0.5.2 lib/daddy/utils/string_utils.rb
daddy-0.5.1 lib/daddy/utils/string_utils.rb
daddy-0.5.0 lib/daddy/utils/string_utils.rb
daddy-0.4.10 lib/daddy/utils/string_utils.rb
daddy-0.4.9 lib/daddy/utils/string_utils.rb
daddy-0.4.8 lib/daddy/utils/string_utils.rb
daddy-0.4.7 lib/daddy/utils/string_utils.rb
daddy-0.4.6 lib/daddy/utils/string_utils.rb
daddy-0.4.5 lib/daddy/utils/string_utils.rb
daddy-0.4.4 lib/daddy/utils/string_utils.rb
daddy-0.4.3 lib/daddy/utils/string_utils.rb
daddy-0.4.2 lib/daddy/utils/string_utils.rb
daddy-0.4.1 lib/daddy/utils/string_utils.rb
daddy-0.4.0 lib/daddy/utils/string_utils.rb
daddy-0.3.38 lib/daddy/utils/string_utils.rb
daddy-0.3.37 lib/daddy/utils/string_utils.rb
daddy-0.3.36 lib/daddy/utils/string_utils.rb
daddy-0.3.35 lib/daddy/utils/string_utils.rb
daddy-0.3.34 lib/daddy/utils/string_utils.rb