power-hours 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a722c581adbe36b6e7e6289d1119b2f532a18982b91b3e89022b81612bbacfd4
4
- data.tar.gz: 999a0de4c442ca2a077496501920bafa4fd0ff5023bb71b1ffdeaf6af2326c23
3
+ metadata.gz: ce07496dcd6c713558c0f2aff72ba0d84f7ed5ccd56dedd561d18a055c968660
4
+ data.tar.gz: ac50321b8fc3644d8061d81364bc6eafafd31206f0eeee0111310b3e91e55e64
5
5
  SHA512:
6
- metadata.gz: a831af010b2a9390a83969e908f1b0e938e4541df4591367c6dc71c60ae0afbc88728729d0761f7a9b6449bb322a27be41fd2b0e2c10a1632a77b6af22316f38
7
- data.tar.gz: 30097f58be66bd9268879d4a8515f430cec1da3ed00f6c82f2b1593deccc4c3d48e4fa5f9cd4d25dff197ff33da7bdcb2f2fa35b16b71806fe8b4e5f42a90af2
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
- in Time
15
- @hour = input.hour
16
- @min = input.min
8
+ when self then input
9
+ when Time then new(hour: input.hour, min: input.min)
17
10
  else
18
- @hour, @min = parse(input)
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
- validate!
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
@@ -1,3 +1,3 @@
1
1
  module OpeningHours
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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 initialize: (time_input input) -> void
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-hours
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Melchert