Class: BeerRecipe::MiscWrapper

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/beer_recipe/misc_wrapper.rb

Constant Summary collapse

DAY =
1440

Instance Method Summary collapse

Methods inherited from Wrapper

#blank?, #format_method, #initialize, #method_missing, #respond_to_missing?, set, wrap

Constructor Details

This class inherits a constructor from BeerRecipe::Wrapper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BeerRecipe::Wrapper

Instance Method Details

#days?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/beer_recipe/misc_wrapper.rb', line 8

def days?
  !blank?(time) && time > DAY
end

#formatted_amountObject



25
26
27
28
29
30
31
# File 'lib/beer_recipe/misc_wrapper.rb', line 25

def formatted_amount
  if large_amount?
    "#{'%.0f' % amount}"
  else
    "#{'%.2f' % (1000 * amount)}"
  end
end

#formatted_timeObject



33
34
35
36
37
38
39
40
# File 'lib/beer_recipe/misc_wrapper.rb', line 33

def formatted_time
  return "" if blank?(time)
  if days?
    "#{'%.0f' % (time / DAY)}"
  else
    "#{'%.0f' % time}"
  end
end

#large_amount?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/beer_recipe/misc_wrapper.rb', line 12

def large_amount?
  amount >= 1
end

#time_unitObject



42
43
44
45
46
47
48
# File 'lib/beer_recipe/misc_wrapper.rb', line 42

def time_unit
  if days?
    'days'
  else
    'minutes'
  end
end

#unitObject



16
17
18
19
20
21
22
23
# File 'lib/beer_recipe/misc_wrapper.rb', line 16

def unit
  # maybe use display_amount directly instead
  if weight?
    large_amount? ? 'kilograms' : 'grams'
  else
    large_amount? ? 'items' : 'ml'
  end
end

#weight?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/beer_recipe/misc_wrapper.rb', line 4

def weight?
  amount_is_weight
end