class Solaar::Term
Attributes
solaar_terms[R]
Public Class Methods
new()
click to toggle source
# File lib/solaar/term.rb, line 9 def initialize @solaar_terms = Solaar::Table end
Public Instance Methods
calc(*args)
click to toggle source
# File lib/solaar/term.rb, line 13 def calc(*args) opts = args.last.is_a?(Hash) ? args.pop : {} opts.merge!(year: self.year) if !opts.key?(:year) if opts[:year].to_i > 2099 || opts[:year].to_i <= 0 raise Exception::OutOfRange.new("Unable to calculate") end if opts.key?(:month) && (1..12).map.include?(opts[:month].to_i) s = opts[:month].to_i*2-2 solaar_terms(opts, [s, s+1]) else solaar_terms(opts, nil) end @terms end
formula(opts={})
click to toggle source
# File lib/solaar/term.rb, line 42 def formula(opts={}) y = @year = opts[:year] month = opts.key?(:month) ? opts[:month].to_i : opts[:m] y = month <= 2 ? y - 1 : y day = opts[:day] + opts[:adj] * (y - 1900) - ((y - 1900) / 4) Hash[date: Time.new(@year, month, day).strftime("%F"), language: { ja: opts[:ja], en: opts[:en] }] end
year()
click to toggle source
# File lib/solaar/term.rb, line 51 def year @year ||= Time.now.year end