Class: OfficeClerk::ShippingMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/office_clerk/shipping_method.rb

Direct Known Subclasses

Pickup

Constant Summary collapse

@@methods =

class stuff after here, global list etc

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ShippingMethod

Returns a new instance of ShippingMethod.



3
4
5
6
7
8
# File 'lib/office_clerk/shipping_method.rb', line 3

def initialize data
  @data = data
  @name = @data[:name]
  @type = @data[:type]
  @description = @data[:description]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/office_clerk/shipping_method.rb', line 9

def data
  @data
end

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/office_clerk/shipping_method.rb', line 9

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/office_clerk/shipping_method.rb', line 9

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/office_clerk/shipping_method.rb', line 9

def type
  @type
end

Class Method Details

.allObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/office_clerk/shipping_method.rb', line 23

def self.all
  return @@methods if @@methods 
  @@methods = {}
  config = OfficeClerk.config(:shipping)
  config.each do |key , method|
    begin
      clas_name = method[:class]
      clas = clas_name.constantize
    rescue
      puts "No such Class #{method[:class]}, check config.yml"
    end
    @@methods[key] = clas.new( method.merge(:type => key) )
  end
  @@methods
end

.method(name) ⇒ Object



38
39
40
41
42
# File 'lib/office_clerk/shipping_method.rb', line 38

def self.method(name)
  return self.all.values.first if name.nil?
  m = self.all[name.to_sym]
  m.blank? ?  self.all.values.first : m
end

Instance Method Details

#available?(basket) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/office_clerk/shipping_method.rb', line 17

def available?(basket)
  true
end

#price_for(basket) ⇒ Object

the relevant interface for a shipping method is a) whether it applies to the order (basket) : available? b) how much sendin costs, price_for(basket)



14
15
16
# File 'lib/office_clerk/shipping_method.rb', line 14

def price_for(basket)
  raise "Not implemented in #{self}"
end