time_pieces 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6939c86325f83d19a213a15367cc310751dac361
4
- data.tar.gz: b1e3f2eaa0466f938812c32947d07f373370da47
3
+ metadata.gz: ecb493c0cd2590abf40b2b7e98daaab1eb2510d5
4
+ data.tar.gz: b76a1db6d6e7e3d2a3d1954787e3ed9d59c45827
5
5
  SHA512:
6
- metadata.gz: 4da90ccab31712d514f8ac2d316bbc3bc244887d9e7ce5f6acde8225a31e9e7d6ee9add2918de1b1a38b538522f2932183db5891960a02271e7a203e32d2d518
7
- data.tar.gz: 442fd4ba05979b1c7f3ddf1d95a0a7d00f8aa1bca56c9a5b1f05e1a76f83ee7c38ecc439dd9183dcd04cb72811c425bb71cb1fed634e780d2751d56f6cb78558
6
+ metadata.gz: 4ca9c9c3276a3770a858817ede3b71677f1085f7d132d4f1516ce940ba7b42495a8f64886813134c46780444071367ac80aa96771bc8afe1ee049a0e8a37e2d3
7
+ data.tar.gz: 1cf8fe07e291d98cdaebb4857405f96678ed05bae640adfded8cfff01ac5c1cef8b9cd7cc5c268e87c969ca6e999b74aaccc13431dac438ec2b55629d0b81182
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- time_pieces (1.0.3)
4
+ time_pieces (1.0.4)
5
5
  bundler
6
6
 
7
7
  GEM
@@ -7,7 +7,7 @@ module TimePieces
7
7
  end
8
8
  end
9
9
  module Duration
10
- attr_accessor :start_at_seconds, :duration_seconds
10
+ attr_accessor :start_at_seconds, :duration_seconds, :lane_number, :lane_count
11
11
  def self.included(base)
12
12
  base.extend(DurationClassMethods)
13
13
  end
@@ -4,6 +4,27 @@ module TimePieces
4
4
  def initialize
5
5
  @time_durations = []
6
6
  end
7
+ def time_durations_in_lanes
8
+
9
+ end
10
+ def clip(start_at_seconds, end_at_seconds)
11
+ new_tds = []
12
+ time_durations.each do |td|
13
+ if td.start_at_seconds < start_at_seconds
14
+ td.start_at_seconds = start_at_seconds
15
+ end
16
+ if td.start_at_seconds + td.duration_seconds > end_at_seconds
17
+ td.duration_seconds = end_at_seconds - start_at_seconds
18
+ end
19
+ new_tds << td
20
+ end
21
+ return new_tds
22
+
23
+ end
24
+ def deep_dup
25
+ return Marshal.load(Marshal.dump(self))
26
+ end
27
+
7
28
  #Adds a new time duration. Removes invalid time durations.
8
29
  def <<(new_td)
9
30
  if new_td.duration_seconds == 0
@@ -0,0 +1,66 @@
1
+ module TimePieces
2
+ class TrafficCop
3
+ attr_accessor :time_durations
4
+ def initialize(time_durations)
5
+ @time_durations = time_durations
6
+ end
7
+ def add_time_durations(time_durations)
8
+ @time_durations += time_durations
9
+ end
10
+ def add_time_set(time_set)
11
+ @time_durations += time_set.time_durations
12
+ end
13
+ def calculate!
14
+ #This handles lane numbers also
15
+ assign_lane_counts!
16
+
17
+ end
18
+ def assign_lane_numbers!
19
+ lanes = [[], [], [], [], [], [], [], [], [], [], [], [], [], []]
20
+ time_durations.sort_by(&:start_at_seconds).each do |td|
21
+ lanes.each_with_index do |lane, lane_number|
22
+ if lane.count > 0
23
+ if lane.last.overlaps?(td)
24
+ next
25
+ else
26
+ lane << td
27
+ break
28
+ end
29
+ else
30
+ lane << td
31
+ break
32
+ end
33
+
34
+ end
35
+ end
36
+ lanes.each_with_index do |lane, lane_number|
37
+ lane.each do |td|
38
+ td.lane_number = lane_number + 1
39
+ puts td.inspect
40
+ puts td.lane_number
41
+ end
42
+ end
43
+ return lanes
44
+ end
45
+ def assign_lane_counts!
46
+ lanes = assign_lane_numbers!
47
+ lanes.reverse.each_with_index do |lane, lane_number_reversed|
48
+ real_lane = lanes.count - lane_number_reversed
49
+ other_lane_recs = []
50
+ lanes.each_with_index do |oth_lane, oth_lane_index|
51
+ break if oth_lane_index >= real_lane
52
+ other_lane_recs += oth_lane
53
+ end
54
+ lane.each do |rec|
55
+ rec.lane_count ||= real_lane
56
+ other_lane_recs.each do |oth_rec|
57
+ if rec.overlaps?(oth_rec)
58
+ oth_rec.lane_count = rec.lane_count if (oth_rec.lane_count.nil?) || (oth_rec.lane_count < rec.lane_count)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module TimePieces
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
data/lib/time_pieces.rb CHANGED
@@ -7,4 +7,5 @@ require 'time_pieces/duration'
7
7
 
8
8
  require 'time_pieces/simple_duration'
9
9
  require 'time_pieces/time_set'
10
+ require 'time_pieces/traffic_cop'
10
11
  require 'chronic'
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_pieces
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant R.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-26 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,8 +96,10 @@ files:
96
96
  - lib/time_pieces/duration.rb
97
97
  - lib/time_pieces/simple_duration.rb
98
98
  - lib/time_pieces/time_set.rb
99
+ - lib/time_pieces/traffic_cop.rb
99
100
  - lib/time_pieces/version.rb
100
101
  - pkg/time_pieces-1.0.2.gem
102
+ - pkg/time_pieces-1.0.3.gem
101
103
  - time_pieces.gemspec
102
104
  homepage: http://github.com/riggleg/time_pieces
103
105
  licenses: