Sha256: e1e7ed1d78eb83974f7392c472e43145fd8af80f78e7565bb050ad1bc147f2e8
Contents?: true
Size: 853 Bytes
Versions: 1
Compression:
Stored size: 853 Bytes
Contents
module Piggybak class TaxCalculator::Percent KEYS = ["state_abbr", "rate"] def self.available?(method, object) abbr = method.metadata.detect { |t| t.key == "state_abbr" }.value if object.is_a?(Cart) state = State.find(object.extra_data["state_id"]) return state.abbr == abbr else if object.billing_address && object.billing_address.state return object.billing_address.state.abbr == abbr end end return false end def self.rate(method, object) taxable_total = 0 if object.is_a?(Cart) taxable_total = object.total else object.line_items.each do |line_item| taxable_total = line_item.total end end (method.metadata.detect { |m| m.key == "rate" }.value.to_f * taxable_total).to_c end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
piggybak-0.2.1 | app/models/piggybak/tax_calculator/percent.rb |