Class: TimePieces::TimeSet
- Inherits:
-
Object
- Object
- TimePieces::TimeSet
- Defined in:
- lib/time_pieces/time_set.rb
Instance Attribute Summary collapse
-
#time_durations ⇒ Object
Returns the value of attribute time_durations.
Instance Method Summary collapse
- #+(other_ts) ⇒ Object
- #-(other_ts) ⇒ Object
-
#<<(new_td) ⇒ Object
Adds a new time duration.
- #>>(subtracting_td) ⇒ Object
- #clip(start_at_seconds, end_at_seconds) ⇒ Object
- #deep_dup ⇒ Object
-
#initialize ⇒ TimeSet
constructor
A new instance of TimeSet.
- #time_durations_in_lanes ⇒ Object
Constructor Details
#initialize ⇒ TimeSet
Returns a new instance of TimeSet.
4 5 6 |
# File 'lib/time_pieces/time_set.rb', line 4 def initialize @time_durations = [] end |
Instance Attribute Details
#time_durations ⇒ Object
Returns the value of attribute time_durations.
3 4 5 |
# File 'lib/time_pieces/time_set.rb', line 3 def time_durations @time_durations end |
Instance Method Details
#+(other_ts) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/time_pieces/time_set.rb', line 67 def +(other_ts) ret_ts = TimeSet.new ret_ts.time_durations = time_durations.map{|td| td} other_ts.time_durations.each do |td| ret_ts << td end return ret_ts end |
#-(other_ts) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/time_pieces/time_set.rb', line 75 def -(other_ts) ret_ts = TimeSet.new ret_ts.time_durations = Array.new(time_durations) other_ts.time_durations.each do |td| ret_ts >> td end return ret_ts end |
#<<(new_td) ⇒ Object
Adds a new time duration. Removes invalid time durations.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/time_pieces/time_set.rb', line 29 def <<(new_td) if new_td.duration_seconds == 0 else new_tds = [] has_combined = false time_durations.each do |td| if new_td.overlaps?(td) || new_td.touches?(td) combined_td = td + new_td combined_td.time_durations.each do |td3| new_tds << td3 end has_combined = true else new_tds << td end end new_tds << new_td unless has_combined self.time_durations = new_tds end return self end |
#>>(subtracting_td) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/time_pieces/time_set.rb', line 51 def >>(subtracting_td) new_tds = [] time_durations.each do |td| if subtracting_td.overlaps?(td) combined_td = td - subtracting_td combined_td.time_durations.each do |td3| new_tds << td3 end else new_tds << td end end self.time_durations = new_tds return self end |
#clip(start_at_seconds, end_at_seconds) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/time_pieces/time_set.rb', line 10 def clip(start_at_seconds, end_at_seconds) new_tds = [] time_durations.each do |td| if td.start_at_seconds < start_at_seconds td.start_at_seconds = start_at_seconds end if td.start_at_seconds + td.duration_seconds > end_at_seconds td.duration_seconds = end_at_seconds - start_at_seconds end new_tds << td end return new_tds end |
#deep_dup ⇒ Object
24 25 26 |
# File 'lib/time_pieces/time_set.rb', line 24 def deep_dup return Marshal.load(Marshal.dump(self)) end |
#time_durations_in_lanes ⇒ Object
7 8 9 |
# File 'lib/time_pieces/time_set.rb', line 7 def time_durations_in_lanes end |