Class: CalcWorkingHours::TimeCard

Inherits:
Object
  • Object
show all
Defined in:
lib/calc_working_hours/time_card.rb

Instance Method Summary collapse

Constructor Details

#initialize(card_id, id) ⇒ TimeCard

Returns a new instance of TimeCard.



7
8
9
10
11
12
# File 'lib/calc_working_hours/time_card.rb', line 7

def initialize(card_id, id)
  @time_card_rows = []
  @card_id = card_id
  @id = id
  self
end

Instance Method Details

#add_row(time_card_rows_obj) ⇒ Object



14
15
16
17
# File 'lib/calc_working_hours/time_card.rb', line 14

def add_row(time_card_rows_obj)
  @time_card_rows << time_card_rows_obj
  self
end

#total_night_timeObject



48
49
50
# File 'lib/calc_working_hours/time_card.rb', line 48

def total_night_time 
  self.total_working_hours_in_range("22:00", "29:00")
end

#total_over_timeObject



27
28
29
30
31
32
33
# File 'lib/calc_working_hours/time_card.rb', line 27

def total_over_time
  array_of_over_time = []
  @time_card_rows.each do |row|
    array_of_over_time << row.over_time.time_string
  end
  return WorkingHours.new("0:00").add_array_time(array_of_over_time).time_string      
end

#total_working_hoursObject



19
20
21
22
23
24
25
# File 'lib/calc_working_hours/time_card.rb', line 19

def total_working_hours
  array_of_working_hours = []
  @time_card_rows.each do |row|
    array_of_working_hours << row.working_hours.time_string
  end
  return WorkingHours.new("0:00").add_array_time(array_of_working_hours).time_string
end

#total_working_hours_in_range(start_range, end_range) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/calc_working_hours/time_card.rb', line 35

def total_working_hours_in_range(start_range, end_range)
  array_of_working_hours_in_range = []
  if start_range == true && end_range == true
    unless CalcHelper.valid_time_format?(start_range) || CalcHelper.valid_time_format?(end_range)
      raise "invalid time format (TimeCard total_working_hours)"
    end
  end
  @time_card_rows.each do |row|
    array_of_working_hours_in_range << row.working_hours_in_range(start_range, end_range)
  end
  return WorkingHours.new("0:00").add_array_time(array_of_working_hours_in_range).time_string
end