cotcube-helpers 0.1.5.4 → 0.1.6

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
  SHA256:
3
- metadata.gz: 97c255de9c0dac3cad83de38b0b8e1eb21af6d27bdf751d58dcc013b9044a7bc
4
- data.tar.gz: 01cb8859f054baf5c87d55d7b718d8261b48428a59e0e728acbb759855526804
3
+ metadata.gz: 0417adfcb0f782bfa9e783dbd1c673a489fca39ce9a0f14fa965eb47aaa64b11
4
+ data.tar.gz: 1b14e149cc6b1bd437d1413dfa49b461c798868959cf97b164a0b3a2e1f72889
5
5
  SHA512:
6
- metadata.gz: 6358bd447301dd4a001b3e4f3ab6e80cd8d2e3073eef1ef9f05fa5c907bf7fd3a19245bd4ea4667bfaebade359e1dc6ea5b24a8f24cf2a8f43bfbb070b6e2567
7
- data.tar.gz: a8876e8e07211f0648b2e646b721e52912bcf117f5b6d811f744368a86ab5c030a2f7ad6542464486fd6502ce9f7c8c51ff9cc5e04e401f45c9289a69e8eb1f5
6
+ metadata.gz: c2babf733929f4ca0705ac2018b075e3b62df051c4918d01fcc6c11b49a7cad2ee68fd8ef26504edc5678c3057a97092de252a34cec2a953f638cd9262c2e65d
7
+ data.tar.gz: 1d9e367613f5b373c73cada786dee68d4e5ccc965573373b39d6419433a5f8131bc553773279d7ba58f2706a63be474448e15cc1e7bce1da63278ad384abeee0
@@ -1,3 +1,7 @@
1
+ ## 0.1.6 (January 15, 2021)
2
+ - removing :ranges from Range#select_within
3
+ - Added Array#select_right_by
4
+
1
5
  ## 0.1.5.4 (January 02, 2021)
2
6
 
3
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5.4
1
+ 0.1.6
@@ -74,4 +74,24 @@ class Array
74
74
  end.reduce(:|)
75
75
  end
76
76
  end
77
+
78
+ def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
79
+ # unless range.is_a? Range and
80
+ # (range.begin.nil? or range.begin.is_a?(Integer)) and
81
+ # (range.end.nil? or range.end.is_a?(Integer))
82
+ # raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
83
+ # end
84
+
85
+ raise ArgumentError, 'No block given.' unless block.is_a? Proc
86
+
87
+ inclusive = true unless exclusive
88
+ if inclusive && exclusive
89
+ raise ArgumentError,
90
+ "Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
91
+ end
92
+
93
+ index = find_index { |obj| block.call(obj) }
94
+
95
+ self[((inclusive ? index : index + 1)..)]
96
+ end
77
97
  end
@@ -2,12 +2,17 @@
2
2
 
3
3
  # Monkey patching the Ruby Core class Range
4
4
  class Range
5
- def to_time_intervals(step:, timezone: Time.find_zone('America/Chicago'), ranges: nil)
5
+ def to_time_intervals(step:,
6
+ timezone: Time.find_zone('America/Chicago'),
7
+ # ranges: nil,
8
+ debug: false)
6
9
  unless step.is_a? ActiveSupport::Duration
7
10
  raise ArgumentError,
8
11
  ":step must be a 'ActiveSupport::Duration', like '15.minutes', but '#{step}' is a '#{step.class}'"
9
12
  end
10
- raise ArgumentError, "Sorry, currently supporting only 15.minutes, 1.hour, 1.day as :step" unless [15.minutes, 60.minutes, 1.hour, 1.day].include? step
13
+ unless [15.minutes, 60.minutes, 1.hour, 1.day].include? step
14
+ raise ArgumentError, 'Sorry, currently supporting only 15.minutes, 1.hour, 1.day as :step'
15
+ end
11
16
 
12
17
  valid_classes = [ActiveSupport::TimeWithZone, Time, Date, DateTime]
13
18
  unless timezone.is_a? ActiveSupport::TimeZone
@@ -30,21 +35,22 @@ class Range
30
35
  # here sub-day and super-day need to be distinguished, as they react differently to daylight time
31
36
  # for super-day, just return an array containing all calendar days
32
37
  if step.to_i >= 1.day
33
- return (starting.to_date..ending.to_date).to_a.map{|x| x.to_datetime}
38
+ (starting.to_date..ending.to_date).to_a.map(&:to_datetime)
34
39
  else
35
40
 
41
+ # sub-day is checked for DST
42
+ # noinspection RubyNilAnalysis
43
+ actual_starting = starting.to_time.to_i
44
+ actual_ending = ending.to_time.to_i
45
+ actual_ending -= 3600 if starting.dst? && (not ending.dst?)
46
+ actual_ending += 3600 if ending.dst? && (not starting.dst?)
47
+
36
48
  ##### The following is the actual big magic line, as it creates the raw target array:
37
49
  #
38
- result = (starting.to_time.to_i..ending.to_time.to_i).step(step).to_a.map { |x| timezone.at(x) }
50
+ result = (actual_starting..actual_ending).step(step).to_a.map { |x| timezone.at(x) }
39
51
  #
40
52
  # ###################<3##
41
53
 
42
-
43
- # sub-day is checked for DST and filtered along provided ranges
44
- # noinspection RubyNilAnalysis
45
- starting_with_dst = result.first.dst?
46
-
47
- # The following lambda is completely misplaces here.
48
54
  # It should probably relocated to Cotcube::Bardata
49
55
  # NOTE: In this current version 12 belongs to it succeeding hour
50
56
  # i.e. 12am is right before 1am and 12pm right before 1pm
@@ -62,26 +68,29 @@ class Range
62
68
  end
63
69
  convert_to_sec_since.call('9:00a.m - 5:00p.m.')
64
70
 
65
- ranges ||= [
66
- 61_200...144_000, # Sun 5pm .. Mon 4pm
67
- 147_600...230_400, # Mon 5pm .. Tue 4pm
68
- 234_000...316_800, # ...
69
- 320_400...403_200,
70
- 406_800...489_600
71
- ]
71
+ # ranges ||= [
72
+ # 61_200...144_000, # Sun 5pm .. Mon 4pm
73
+ # 147_600...230_400, # Mon 5pm .. Tue 4pm
74
+ # 234_000...316_800, # ...
75
+ # 320_400...403_200,
76
+ # 406_800...489_600
77
+ # ]
72
78
 
73
79
  # if there was a change towards daylight saving time, subtract 1 hour, otherwise add 1 hour
74
80
  result.map! do |time|
75
- if (not starting_with_dst) && time.dst?
76
- time - 3600
77
- elsif starting_with_dst && (not time.dst?)
78
- time + 3600
79
- else
80
- time
81
+ print "#{time}\t" if debug
82
+ if (not starting.dst?) && time.dst?
83
+ time -= 3600
84
+ print "Time reduced (not starting_DST, but current\t" if debug
85
+ elsif starting.dst? && (not time.dst?)
86
+ time += 3600
87
+ print "Time extended (starting DST, but not current\t" if debug
81
88
  end
89
+ puts "#{time} " if debug
90
+ time
82
91
  end
83
92
 
84
- result.select_within(ranges: ranges) { |x| x.to_datetime.to_seconds_since_monday_morning }
93
+ result # .select_within(ranges: ranges) { |x| x.to_datetime.to_seconds_since_sunday_morning }
85
94
  end
86
95
  end
87
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport