Class: CalcWorkingHours::TimeCardRow
- Inherits:
-
Object
- Object
- CalcWorkingHours::TimeCardRow
- Defined in:
- lib/calc_working_hours/time_card_row.rb
Instance Attribute Summary collapse
-
#break_time ⇒ Object
readonly
Returns the value of attribute break_time.
-
#date_string ⇒ Object
readonly
Returns the value of attribute date_string.
-
#ending_time ⇒ Object
readonly
Returns the value of attribute ending_time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#over_time ⇒ Object
readonly
Returns the value of attribute over_time.
-
#starting_time ⇒ Object
readonly
Returns the value of attribute starting_time.
-
#time_point ⇒ Object
readonly
Returns the value of attribute time_point.
-
#working_hours ⇒ Object
readonly
Returns the value of attribute working_hours.
Instance Method Summary collapse
- #between_10pm_and_5am ⇒ Object
-
#initialize(date_string, starting_time, ending_time, auto_correction, *break_time) ⇒ TimeCardRow
constructor
A new instance of TimeCardRow.
- #set_fixed_working_hours(time) ⇒ Object
- #working_hours_in_range(start_range, end_range) ⇒ Object
Constructor Details
#initialize(date_string, starting_time, ending_time, auto_correction, *break_time) ⇒ TimeCardRow
Returns a new instance of TimeCardRow.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/calc_working_hours/time_card_row.rb', line 9 def initialize(date_string, starting_time, ending_time, auto_correction, *break_time) if auto_correction unless CalcHelper.valid_time_order?(starting_time, ending_time) et = WorkingHours.new(ending_time) ending_time = et.add_time("24:00").time_string end unless break_time.empty? break_time.map! do |time| unless CalcHelper.valid_time_order?(starting_time, time[0]) et = WorkingHours.new(time[0]) time[0] = et.add_time("24:00").time_string end unless CalcHelper.valid_time_order?(starting_time, time[1]) et = WorkingHours.new(time[1]) time[1] = et.add_time("24:00").time_string end [time[0], time[1]] end end end unless date_string.class == String raise "failure set_date (date should string class)! TimeCardRow class" end unless CalcHelper.valid_time_format?(starting_time) && CalcHelper.valid_time_format?(ending_time) raise "failure initialize (invalid time format! TimeCardRow class)" end unless CalcHelper.valid_time_order?(starting_time, ending_time) raise "failure initialize (invalid time order! TimeCardRow class)" end unless break_time.empty? unless CalcHelper.valid_break_time?(break_time, starting_time, ending_time) raise "failure initialize (invalid break time! TimeCardRow class)" end end break_time.each do |time| unless CalcHelper.valid_time_order?(time[0], time[1]) raise "failure initialize (invalid time order(break time)! TimeCardRow class)" end end total_break_time_string = "0:00" unless break_time.empty? total_break_time_string = CalcHelper.total_break_time(break_time).time_string end @date_string = date_string @starting_time = starting_time @ending_time = ending_time @break_time = break_time @working_hours = WorkingHours.new(ending_time).minus_time(starting_time).minus_time(total_break_time_string) @over_time = WorkingHours.new("0:00") if @over_time == nil @time_point = [] @time_point << starting_time unless break_time.empty? break_time.each do |bt| @time_point << bt[0] @time_point << bt[1] end end @time_point << ending_time self end |
Instance Attribute Details
#break_time ⇒ Object (readonly)
Returns the value of attribute break_time.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def break_time @break_time end |
#date_string ⇒ Object (readonly)
Returns the value of attribute date_string.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def date_string @date_string end |
#ending_time ⇒ Object (readonly)
Returns the value of attribute ending_time.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def ending_time @ending_time end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def id @id end |
#over_time ⇒ Object (readonly)
Returns the value of attribute over_time.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def over_time @over_time end |
#starting_time ⇒ Object (readonly)
Returns the value of attribute starting_time.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def starting_time @starting_time end |
#time_point ⇒ Object (readonly)
Returns the value of attribute time_point.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def time_point @time_point end |
#working_hours ⇒ Object (readonly)
Returns the value of attribute working_hours.
8 9 10 |
# File 'lib/calc_working_hours/time_card_row.rb', line 8 def working_hours @working_hours end |
Instance Method Details
#between_10pm_and_5am ⇒ Object
111 112 113 |
# File 'lib/calc_working_hours/time_card_row.rb', line 111 def between_10pm_and_5am self.working_hours_in_range("22:00", "29:00") end |
#set_fixed_working_hours(time) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/calc_working_hours/time_card_row.rb', line 77 def set_fixed_working_hours(time) time = WorkingHours.new(time) working_hours = WorkingHours.new(@working_hours.time_string) if working_hours.minute < time.minute @over_time = working_hours.minus_time(working_hours.time_string) else @over_time = working_hours.minus_time(time.time_string) end self end |
#working_hours_in_range(start_range, end_range) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/calc_working_hours/time_card_row.rb', line 88 def working_hours_in_range(start_range, end_range) i = @time_point.size / 2 starting_time, ending_time = "" array_of_working_hours = [] for counter in 1..i counter = 2 * counter - 2 starting_time = @time_point[counter] ending_time = @time_point[counter + 1] if CalcHelper.valid_range?(end_range, starting_time) || CalcHelper.valid_range?(ending_time, start_range) elsif CalcHelper.valid_range?(start_range, starting_time) && CalcHelper.valid_range?(end_range, ending_time) array_of_working_hours << WorkingHours.new(end_range).minus_time(starting_time).time_string elsif CalcHelper.valid_range?(starting_time, start_range) && CalcHelper.valid_range?(end_range, ending_time) array_of_working_hours << WorkingHours.new(end_range).minus_time(start_range).time_string elsif CalcHelper.valid_range?(starting_time, start_range) && CalcHelper.valid_range?(ending_time, end_range) array_of_working_hours << WorkingHours.new(ending_time).minus_time(start_range).time_string elsif CalcHelper.valid_range?(start_range, starting_time) && CalcHelper.valid_range?(ending_time, end_range) array_of_working_hours << WorkingHours.new(ending_time).minus_time(starting_time).time_string end end return WorkingHours.new("0:00").add_array_time(array_of_working_hours).time_string end |