Class: AusPost::DRC::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/aus_post/drc/calculator.rb

Constant Summary collapse

DRC_BASE_URI =
"http://drc.edeliver.com.au/rateCalc.asp"

Instance Method Summary collapse

Constructor Details

#initialize(parcel) ⇒ Calculator

Returns a new instance of Calculator.



10
11
12
13
14
15
16
# File 'lib/aus_post/drc/calculator.rb', line 10

def initialize(parcel)
  @parcel           = parcel
  @calculated       = false
  @charge           = nil
  @charge_as_string = nil
  @days             = nil
end

Instance Method Details

#calculateObject

Once off thing.



19
20
21
22
23
24
25
26
# File 'lib/aus_post/drc/calculator.rb', line 19

def calculate
  unless @calculated
    uri = URI.parse("#{DRC_BASE_URI}?#{@parcel.to_params}")
    response = Net::HTTP.get(uri)
    process_response response
    @calculated = true
  end
end

#chargeObject



38
39
40
41
# File 'lib/aus_post/drc/calculator.rb', line 38

def charge
  calculate
  @charge
end

#charge!Object



53
54
55
# File 'lib/aus_post/drc/calculator.rb', line 53

def charge!
  value_with_exception :charge
end

#charge_as_stringObject



48
49
50
51
# File 'lib/aus_post/drc/calculator.rb', line 48

def charge_as_string
  calculate
  @charge_as_string
end

#charge_as_string!Object



61
62
63
# File 'lib/aus_post/drc/calculator.rb', line 61

def charge_as_string!
  value_with_exception :charge_as_string
end

#daysObject



43
44
45
46
# File 'lib/aus_post/drc/calculator.rb', line 43

def days
  calculate
  @days
end

#days!Object



57
58
59
# File 'lib/aus_post/drc/calculator.rb', line 57

def days!
  value_with_exception :days
end

#has_charge?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/aus_post/drc/calculator.rb', line 28

def has_charge?
  calculate
  !@charge.nil?
end

#has_days?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/aus_post/drc/calculator.rb', line 33

def has_days?
  calculate
  !@days.nil?
end