class Japanese
Public Class Methods
convert_wareki(year)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 3 def convert_wareki(year) [ ["令和", 2019], ["平成", 1989], ["昭和", 1926], ["大正", 1912], ["明治", 1868], ].each do |a| gengo, start_at = a wareki = year - start_at + 1 if wareki > 0 wareki = "元" if wareki == 1 return "#{gengo}#{wareki}" end end end
is_hiragana?(str)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 25 def is_hiragana?(str) return nil if !str || str.empty? return /^[ぁ-ん\-ー―−]+$/ =~ str end
is_katakana?(str)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 20 def is_katakana?(str) return nil if !str || str.empty? return /^[ァ-ン\-ー―−]+$/ =~ str end
to_date_str(tm)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 50 def to_date_str(tm) return nil unless tm return "%d年%2d月%2d日" %[ tm.year, tm.mon, tm.mday] end
to_datetime_str(tm)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 45 def to_datetime_str(tm) return nil unless tm return "%d年%2d月%2d日 %2d:%02d:%02d" %[ tm.year, tm.mon, tm.mday, tm.hour, tm.min, tm.sec ] end
to_hiragana(str)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 30 def to_hiragana(str) return nil if !str return str.tr("ァ-ン\-ー―−", "ぁ-ん\-ー―−") end
to_katakana(str)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 35 def to_katakana(str) return nil if !str return str.tr("ぁ-ん\-ー―−", "ァ-ン\-ー―−") end
to_wday(wday)
click to toggle source
# File lib/ezframe/japanese_utils.rb, line 40 def to_wday(wday) return nil unless wday return %w(日 月 火 水 木 金 土)[wday] end