Sha256: e9654d1b671ba479811277ea53b08d91964dcebc7df33674d0fc1a1d1c9a28f4
Contents?: true
Size: 939 Bytes
Versions: 5
Compression:
Stored size: 939 Bytes
Contents
require 'yaml' module TaxJp class Gengou @@_gengou = TaxJp::Utils.load_yaml('元号.yml') def self.to_seireki(gengou, year_jp) target_gengou = nil @@_gengou.invert.keys.each do |start_gengou| if start_gengou == gengou.to_s target_gengou = start_gengou break end end return nil unless target_gengou start_year = @@_gengou.invert[target_gengou].to_i return (start_year + year_jp.to_i - 1).to_s end def self.to_wareki(year) return nil unless year.present? target_year = nil @@_gengou.keys.sort.each do |start_year| break if start_year.to_i > year.to_i target_year = start_year end return nil unless target_year gengou = @@_gengou[target_year] year_jp = year - target_year + 1 return gengou + (year_jp == 1 ? '元' : year_jp.to_s) end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
tax_jp-0.3.6 | lib/tax_jp/gengou.rb |
tax_jp-0.3.5 | lib/tax_jp/gengou.rb |
tax_jp-0.3.4 | lib/tax_jp/gengou.rb |
tax_jp-0.3.3 | lib/tax_jp/gengou.rb |
tax_jp-0.3.2 | lib/tax_jp/gengou.rb |