class CalcWorkingHours::WorkingHours

Attributes

minute[R]
time_string[R]

Public Class Methods

new(str) click to toggle source
# File lib/calc_working_hours/working_hours.rb, line 6
def initialize(str)
  if CalcHelper.valid_working_hours_format?(str)
    @time_string = str
    self.to_minute
    self
  else
    raise "failure initialize (invalid time format!)"
  end
end

Public Instance Methods

add_array_time(array) click to toggle source
# File lib/calc_working_hours/working_hours.rb, line 30
def add_array_time(array)
  array.each do |str|
    self.add_time(str)
  end
  self
end
add_time(str) click to toggle source
# File lib/calc_working_hours/working_hours.rb, line 20
def add_time(str)
  if CalcHelper.valid_working_hours_format?(str)
    @minute = @minute + CalcHelper.change_to_minute(str)
    @time_string = CalcHelper.change_to_time_string(@minute)
    self
  else
    raise "failure add_time (invalid time format!)"
  end
end
minus_time(str) click to toggle source
# File lib/calc_working_hours/working_hours.rb, line 37
def minus_time(str)
  if CalcHelper.valid_working_hours_format?(str)
    minute = @minute - CalcHelper.change_to_minute(str)
    if minute >= 0
      @minute = minute
      @time_string = CalcHelper.change_to_time_string(@minute)
      self
    else 
      raise "failure add_time (invalid time format!)"
    end
  end
end
to_minute() click to toggle source
# File lib/calc_working_hours/working_hours.rb, line 16
def to_minute
  @minute = CalcHelper.change_to_minute(@time_string)
end