Class: ODDB::State::Drugs::Compare::Comparison::PackageFacade

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Comparable
Defined in:
src/state/drugs/compare.rb,
test/test_model/comparison.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PackageFacade) initialize(package, original)

A new instance of PackageFacade



19
20
21
22
23
# File 'src/state/drugs/compare.rb', line 19

def initialize(package, original)
  @original = original
  @package = package
  super(package)
end

Instance Attribute Details

- (Object) package (readonly)

Returns the value of attribute package



18
19
20
# File 'test/test_model/comparison.rb', line 18

def package
  @package
end

Instance Method Details

- (Object) <=>(other)



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'src/state/drugs/compare.rb', line 35

def <=>(other)
  ppp = @package.price_public.to_i
  opp = other.price_public.to_i
  if([ppp, opp].any? { |pp| pp <= 0 } \
    && (res = opp-ppp) != 0)
    return res
  end
  res = price_difference.to_f <=> other.price_difference.to_f 
  res = ppp <=> opp if res == 0
  res = @package.comparable_size <=> other.comparable_size if res == 0
  res = @package.name_base <=> other.name_base if res == 0
  res
end

- (Object) price_difference



24
25
26
27
28
29
30
31
32
33
34
# File 'src/state/drugs/compare.rb', line 24

def price_difference
  oprice = @original.price_public.to_f
  pprice = @package.price_public.to_f
  osize = @original.comparable_size.qty.to_f 
  psize = @package.comparable_size.qty.to_f
  unless ( (@original == @package) \
    || (oprice <= 0) || (pprice <= 0) \
    || (osize <= 0) || (psize <= 0))
    ( (osize * pprice) / (psize * oprice) ) - 1.0
  end
end