power-hours 0.1.0 → 0.1.2
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 +4 -4
- data/lib/opening_hours/time_of_day.rb +11 -26
- data/lib/opening_hours/version.rb +1 -1
- data/sig/power/hours.rbs +2 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce07496dcd6c713558c0f2aff72ba0d84f7ed5ccd56dedd561d18a055c968660
|
|
4
|
+
data.tar.gz: ac50321b8fc3644d8061d81364bc6eafafd31206f0eeee0111310b3e91e55e64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd0e0588cd49d93043077f1cb195c6a63e575623a58b998c50a577f859614dbe2bf1f3fe689164f6e326182dcbdb1d5fc3dca9bf50d9e4434ac4815c876d72d7
|
|
7
|
+
data.tar.gz: 850ebcaa28862ad8e05d98cb860b9642d0dd6b6fe675a18da8b18d2fd1b1c2cd1f872de72896a27ce51cd0c3ab364ba221cbf706aaea49d8f16bcf7f0faa5989
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
module OpeningHours
|
|
2
|
-
class TimeOfDay
|
|
2
|
+
class TimeOfDay < Data.define(:hour, :min)
|
|
3
3
|
include Comparable
|
|
4
4
|
REGEX = /\A(\d{1,2})(?::(\d{1,2}))?\z/.freeze
|
|
5
5
|
|
|
6
6
|
def self.[](input)
|
|
7
|
-
input.is_a?(self) ? input : new(input)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
attr_reader :hour, :min
|
|
11
|
-
|
|
12
|
-
def initialize(input)
|
|
13
7
|
case input
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@min = input.min
|
|
8
|
+
when self then input
|
|
9
|
+
when Time then new(hour: input.hour, min: input.min)
|
|
17
10
|
else
|
|
18
|
-
|
|
11
|
+
match = REGEX.match(input.to_s.strip)
|
|
12
|
+
raise ArgumentError, "Invalid time: #{input.inspect}" unless match
|
|
13
|
+
new(hour: match[1].to_i, min: (match[2] || 0).to_i)
|
|
19
14
|
end
|
|
15
|
+
end
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
def initialize(hour: 0, min: 0)
|
|
18
|
+
super
|
|
19
|
+
raise ArgumentError unless hour.between?(0, 23)
|
|
20
|
+
raise ArgumentError unless min.between?(0, 59)
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
def <=>(other)
|
|
@@ -32,19 +31,5 @@ module OpeningHours
|
|
|
32
31
|
def to_s
|
|
33
32
|
format("%02d:%02d", hour, min)
|
|
34
33
|
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def parse(input)
|
|
39
|
-
match = REGEX.match(input.to_s.strip)
|
|
40
|
-
raise ArgumentError, "Invalid time: #{input.inspect}" unless match
|
|
41
|
-
|
|
42
|
-
[match[1].to_i, (match[2] || 0).to_i]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def validate!
|
|
46
|
-
raise ArgumentError unless hour.between?(0, 23)
|
|
47
|
-
raise ArgumentError unless min.between?(0, 59)
|
|
48
|
-
end
|
|
49
34
|
end
|
|
50
35
|
end
|
data/sig/power/hours.rbs
CHANGED
|
@@ -14,7 +14,8 @@ module OpeningHours
|
|
|
14
14
|
attr_reader min: Integer
|
|
15
15
|
|
|
16
16
|
def self.[]: (time_input input) -> OpeningHours::TimeOfDay
|
|
17
|
-
def
|
|
17
|
+
def self.new: (?hour: Integer, ?min: Integer) -> OpeningHours::TimeOfDay
|
|
18
|
+
def initialize: (?hour: Integer, ?min: Integer) -> void
|
|
18
19
|
|
|
19
20
|
def <=>: (time_input other) -> Integer?
|
|
20
21
|
def to_minutes: () -> Integer
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: power-hours
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Kevin Melchert
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
@@ -32,12 +32,12 @@ files:
|
|
|
32
32
|
- lib/opening_hours/version.rb
|
|
33
33
|
- lib/power/hours.rb
|
|
34
34
|
- sig/power/hours.rbs
|
|
35
|
-
homepage: https://github.com/
|
|
35
|
+
homepage: https://github.com/max-power/power-hours
|
|
36
36
|
licenses:
|
|
37
37
|
- MIT
|
|
38
38
|
metadata:
|
|
39
|
-
homepage_uri: https://github.com/
|
|
40
|
-
source_code_uri: https://github.com/
|
|
39
|
+
homepage_uri: https://github.com/max-power/power-hours
|
|
40
|
+
source_code_uri: https://github.com/max-power/power-hours/tree/main
|
|
41
41
|
rdoc_options: []
|
|
42
42
|
require_paths:
|
|
43
43
|
- lib
|