module Shouhizei

Constants

Round
RoundDown
RoundUp
VERSION

Public Class Methods

config() click to toggle source
# File lib/shouhizei.rb, line 29
def self.config
  @@config ||= {rounding: RoundDown}
end
including(price:, time: Time.current, reduced: false, rounding: config[:rounding]) click to toggle source
# File lib/shouhizei.rb, line 21
def self.including(price:, time: Time.current, reduced: false, rounding: config[:rounding])
  including_price = price + price * rate_on(time, reduced: reduced)

  return including_price.round if rounding == Round
  return including_price.ceil if rounding == RoundUp
  including_price.floor
end
rate_on(time = Time.current, reduced: false) click to toggle source
# File lib/shouhizei.rb, line 11
def self.rate_on(time = Time.current, reduced: false)
  date = time.in_time_zone('Asia/Tokyo').to_date
  rate_list.reverse_each do |key_date, rate|
    rate_key = reduced && rate['reduced'] ? 'reduced' : 'default'

    return rate[rate_key].to_r if date >= key_date
  end
  0.0r
end

Private Class Methods

rate_list() click to toggle source
# File lib/shouhizei.rb, line 35
def self.rate_list
  @@rate_list ||= YAML.load_file(File.expand_path('./../rate_list.yml', __FILE__))
end