class Thirsty::Today::Add
Attributes
amount[R]
Public Class Methods
new(amount)
click to toggle source
# File lib/thirsty/today/add.rb, line 8 def initialize(amount) @amount = amount end
Public Instance Methods
call()
click to toggle source
# File lib/thirsty/today/add.rb, line 12 def call validate_amount update_amount end
Private Instance Methods
current()
click to toggle source
# File lib/thirsty/today/add.rb, line 32 def current @current ||= Get.call end
normalized_amount()
click to toggle source
# File lib/thirsty/today/add.rb, line 27 def normalized_amount amount_f = amount.to_f amount_f < 3 ? amount_f : amount_f / 1000 end
update_amount()
click to toggle source
# File lib/thirsty/today/add.rb, line 36 def update_amount full_amount = current + normalized_amount File.open(File.expand_path("~/.thirsty/#{Date.today}.txt"), 'w+') { |f| f << full_amount } end
validate_amount()
click to toggle source
# File lib/thirsty/today/add.rb, line 21 def validate_amount if amount !~ /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/ raise ArgumentError, "invalid value for Float(): #{requirement.inspect}" end end