Class: GBWorkDay::Interval
- Inherits:
-
Object
- Object
- GBWorkDay::Interval
- Defined in:
- lib/gb_work_day/interval.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #endpoints ⇒ Object
-
#initialize(start_time, end_time, params = Hash.new) ⇒ Interval
constructor
A new instance of Interval.
-
#work_days ⇒ Integer
(also: #duration)
Number of working days in a given period.
Constructor Details
#initialize(start_time, end_time, params = Hash.new) ⇒ Interval
Returns a new instance of Interval.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gb_work_day/interval.rb', line 14 def initialize(start_time, end_time, params = Hash.new) @start_time = start_time @end_time = end_time @symbol = 1 revert if @start_time > @end_time @working_week = params[:week] unless @working_week if params[:work_days] work_days = params.fetch(:work_days, 7) @working_week = WorkWeek.new work_days else @working_week = WorkWeek.current end end @work_start_time = next_work_day @start_time @work_end_time = next_work_day @end_time end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
8 9 10 |
# File 'lib/gb_work_day/interval.rb', line 8 def end_time @end_time end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/gb_work_day/interval.rb', line 8 def start_time @start_time end |
Instance Method Details
#endpoints ⇒ Object
51 52 53 |
# File 'lib/gb_work_day/interval.rb', line 51 def endpoints [start_time, end_time] end |
#work_days ⇒ Integer Also known as: duration
Returns Number of working days in a given period.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gb_work_day/interval.rb', line 33 def work_days if @working_week.work_days_per_week == 7 work_days = end_time.minus_without_work_duration(start_time).to_i else monday_before_start = @work_start_time.beginning_of_week monday_before_end = @work_end_time.beginning_of_week full_week_days = monday_before_end.minus_without_work_duration(monday_before_start).to_i days_without_weekends = full_week_days - (full_week_days / 7) * @working_week.free_days_per_week partial_week_days = @work_end_time.wday - @work_start_time.wday work_days = days_without_weekends + partial_week_days end Duration.new(work_days * @symbol, @working_week) end |