Class: Google4R::Checkout::TaxTable

Inherits:
Object
  • Object
show all
Defined in:
lib/google4r/checkout/shared.rb

Overview

A TaxTable is an ordered array of TaxRule objects. You should create the TaxRule instances using #create_rule

You must set up a tax table factory and should only create tax tables from within its temporal factory method as described in the class documentation of Frontend.

Each tax table must have one or more tax rules.

Example

include Google4R::Checkout

tax_free_table = TaxTable.new(false)
tax_free_table.name = "default table"
tax_free_table.create_rule do |rule|
  rule.area = UsCountryArea.new(UsCountryArea::ALL)
  rule.rate = 0.0
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(standalone) ⇒ TaxTable

Returns a new instance of TaxTable.



299
300
301
302
303
# File 'lib/google4r/checkout/shared.rb', line 299

def initialize(standalone)
  @rules = Array.new
  
  @standalone = standalone
end

Instance Attribute Details

#nameObject

The name of this tax table (string, required).



290
291
292
# File 'lib/google4r/checkout/shared.rb', line 290

def name
  @name
end

#rulesObject (readonly)

An Array of the TaxRule objects that this TaxTable contains. Use #create_rule do add to this Array but do not change it directly.



294
295
296
# File 'lib/google4r/checkout/shared.rb', line 294

def rules
  @rules
end

#standaloneObject (readonly)

Boolean, true iff the table’s standalone attribute is to be set to “true”.



297
298
299
# File 'lib/google4r/checkout/shared.rb', line 297

def standalone
  @standalone
end

Instance Method Details

#create_rule {|rule| ... } ⇒ Object

Use this method to add a new TaxRule to the table. If you use a block with this method then the block will called with the newly created rule for the parameter. The method will return the new rule in any case.

Yields:

  • (rule)


308
309
310
311
312
313
314
315
316
# File 'lib/google4r/checkout/shared.rb', line 308

def create_rule(&block)
  rule = TaxRule.new(self)
  @rules << rule
  
  # Pass the newly generated rule to the given block to set its attributes.
  yield(rule) if block_given?
  
  return rule
end