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 +4 -4
- data/lib/forty_time.rb +11 -5
- data/lib/null_forty_time.rb +19 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c4afd16ee13a0f0b5f97872c04e7bfda6bdb222c985206bdb28bb49d6f11f91
|
4
|
+
data.tar.gz: c881747880e6f021f42fa4fcaeb91762bef8e7c4eb46ba8cef02af2d24be2d12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
15
|
-
|
15
|
+
minutes = parse_string(input)
|
16
|
+
new(minutes)
|
17
|
+
end
|
16
18
|
|
17
|
-
|
19
|
+
def self.parse_string(string)
|
20
|
+
hours, extra = string.split(':').map(&:to_i)
|
21
|
+
extra *= -1 if string[0] == '-'
|
18
22
|
|
19
|
-
|
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'
|
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.
|
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-
|
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
|