Class: CalcWorkingHours::WorkingHours
- Inherits:
-
Object
- Object
- CalcWorkingHours::WorkingHours
- Defined in:
- lib/calc_working_hours/working_hours.rb
Instance Attribute Summary collapse
-
#minute ⇒ Object
readonly
Returns the value of attribute minute.
-
#time_string ⇒ Object
readonly
Returns the value of attribute time_string.
Instance Method Summary collapse
- #add_array_time(array) ⇒ Object
- #add_time(str) ⇒ Object
-
#initialize(str) ⇒ WorkingHours
constructor
A new instance of WorkingHours.
- #minus_time(str) ⇒ Object
- #to_minute ⇒ Object
Constructor Details
#initialize(str) ⇒ WorkingHours
Returns a new instance of WorkingHours.
7 8 9 10 11 12 13 14 15 |
# File 'lib/calc_working_hours/working_hours.rb', line 7 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 |
Instance Attribute Details
#minute ⇒ Object (readonly)
Returns the value of attribute minute.
6 7 8 |
# File 'lib/calc_working_hours/working_hours.rb', line 6 def minute @minute end |
#time_string ⇒ Object (readonly)
Returns the value of attribute time_string.
6 7 8 |
# File 'lib/calc_working_hours/working_hours.rb', line 6 def time_string @time_string end |
Instance Method Details
#add_array_time(array) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/calc_working_hours/working_hours.rb', line 31 def add_array_time(array) array.each do |str| self.add_time(str) end self end |
#add_time(str) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/calc_working_hours/working_hours.rb', line 21 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) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/calc_working_hours/working_hours.rb', line 38 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 ⇒ Object
17 18 19 |
# File 'lib/calc_working_hours/working_hours.rb', line 17 def to_minute @minute = CalcHelper.change_to_minute(@time_string) end |