Class: Daddy::Utils::StringUtils
- Inherits:
-
Object
- Object
- Daddy::Utils::StringUtils
- Defined in:
- lib/daddy/utils/string_utils.rb
Class Method Summary collapse
- .current_time(now = nil) ⇒ Object
- .rand(length = 8) ⇒ Object
- .to_han(s) ⇒ Object
- .to_hiragana(s) ⇒ Object
- .to_katakana(s) ⇒ Object
- .to_zen(s) ⇒ Object
Class Method Details
.current_time(now = nil) ⇒ Object
27 28 29 30 |
# File 'lib/daddy/utils/string_utils.rb', line 27 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 |
.rand(length = 8) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/daddy/utils/string_utils.rb', line 32 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 |
.to_han(s) ⇒ Object
22 23 24 25 |
# File 'lib/daddy/utils/string_utils.rb', line 22 def self.to_han(s) return s if is_empty(s) NKF::nkf('-Wwxm0Z0', s) end |
.to_hiragana(s) ⇒ Object
7 8 9 10 |
# File 'lib/daddy/utils/string_utils.rb', line 7 def self.to_hiragana(s) return s if is_empty(s) NKF::nkf('-Ww --hiragana', s) end |
.to_katakana(s) ⇒ Object
12 13 14 15 |
# File 'lib/daddy/utils/string_utils.rb', line 12 def self.to_katakana(s) return s if is_empty(s) NKF::nkf('-Ww --katakana', s) end |
.to_zen(s) ⇒ Object
17 18 19 20 |
# File 'lib/daddy/utils/string_utils.rb', line 17 def self.to_zen(s) return s if is_empty(s) NKF::nkf('-WwXm0', s) end |