forty_time 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 005fa602c9aebd4292f9f6f11c8b59886f0db7570a1ebe11bb90642999c211ba
4
- data.tar.gz: 549a50af8e1baedf11b3967d9df1b79316f105e4833b0f2ed7ed973dc2e13f1c
3
+ metadata.gz: 8c4afd16ee13a0f0b5f97872c04e7bfda6bdb222c985206bdb28bb49d6f11f91
4
+ data.tar.gz: c881747880e6f021f42fa4fcaeb91762bef8e7c4eb46ba8cef02af2d24be2d12
5
5
  SHA512:
6
- metadata.gz: eb5534b2122a21553c39e1316adc5073d6c65ae5cd83b94f2bada84cb8dcc0d804d4fd97ba3fc8871870cb49d4edbd779d995587adf1105e51af62566eb78502
7
- data.tar.gz: d61bd7b39ffe857ccd7371490f6ae81599cd9a96e572d35718eeb27d986da2441231ac76134d5e4efb832918f1e27a2f0449e83c681a50e36405c959964b6bbe
6
+ metadata.gz: 6dec9f4c42417413fc761e2016022097f62fc7f5275e51314c20266b6de8e7467a302f8c56d7d37b39057821fe6d33653f5114db0e759c2adf3cbf43d2c0cba7
7
+ data.tar.gz: 8e82ee8428376243120688186d9cce357550669e5f371fec42f950490d6632955cd0a81dd5feba76644d41359cfcbed13dc6e493a46f15617e84b8b2e460d356
data/lib/forty_time.rb CHANGED
@@ -1,22 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FortyTime
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
 
6
6
  class ParseError < StandardError; end
7
7
 
8
8
  def self.parse(input)
9
+ return NullFortyTime.new if input.nil?
9
10
  return new(input) if input.is_a? Integer
10
11
 
11
12
  can_parse_string = input.is_a?(String) && input.match?(/:/)
12
13
  raise ParseError unless can_parse_string
13
14
 
14
- hours, extra = input.split(':').map(&:to_i)
15
- extra *= -1 if input[0] == '-'
15
+ minutes = parse_string(input)
16
+ new(minutes)
17
+ end
16
18
 
17
- minutes = hours * 60 + extra
19
+ def self.parse_string(string)
20
+ hours, extra = string.split(':').map(&:to_i)
21
+ extra *= -1 if string[0] == '-'
18
22
 
19
- new(minutes)
23
+ hours * 60 + extra
20
24
  end
21
25
 
22
26
  attr_accessor :minutes
@@ -49,3 +53,5 @@ class FortyTime
49
53
  [hours, extra].join(':')
50
54
  end
51
55
  end
56
+
57
+ require_relative './null_forty_time'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NullFortyTime < FortyTime
4
+ def initialize
5
+ super(0)
6
+ end
7
+
8
+ def +(other)
9
+ other
10
+ end
11
+
12
+ def -(other)
13
+ other
14
+ end
15
+
16
+ def to_s
17
+ ''
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forty_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Allured
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-11 00:00:00.000000000 Z
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem helps one go between intergers and strings to represent time
14
14
  amounts.
@@ -30,6 +30,7 @@ files:
30
30
  - bin/setup
31
31
  - forty_time.gemspec
32
32
  - lib/forty_time.rb
33
+ - lib/null_forty_time.rb
33
34
  homepage: https://www.fortyeven.com/
34
35
  licenses:
35
36
  - MIT