hour-ruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hour.rb +9 -0
  3. data/spec/hour_spec.rb +44 -21
  4. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc01dd18ded1207c7b8983eb21f9ef335318760adfc8629ac21231666015b4d0
4
- data.tar.gz: 1d992b5f668e305cbf50f26142c1ea52d1183ca459686ff6c2d2c426497d52ae
3
+ metadata.gz: d933c2d8c4bf1a55e212a1f3339e0eadd990dc00d5a9adfba81bd7ffed47ff03
4
+ data.tar.gz: c9bc666450f39434c9f3f406050b7f496c717c9a9a67255806007ff9b70355d2
5
5
  SHA512:
6
- metadata.gz: e19b77cd897cbf3800e87d92ff3d67c8bb796aa0e52abf37f3d272b893ef00d13e7137a9738589cd4a5c60147850a17b96aa5e99137e7ed3d70a49d2bcce0f84
7
- data.tar.gz: f661487e9153b7d90c8e6380f447bd1f8c42088010cc8f2a51be58bfa0881a393443609e46883f34be9a655b82a67f2ba219c573633014aa0c390755dc6bdd43
6
+ metadata.gz: 60c5f824af31d47aaa49ddedc052a60330403046fff831c4b83514f5c033701227735d8c899569d45671dd2512494bae0218ef37ce5a98c9e4f52d51db781ba5
7
+ data.tar.gz: 1a5caab48563ba99f2e30b9c86f99a47299be769bda0c41b6e812621bbd37d0af3dbcfeac07aa9f4ea5bead14aaf6c982dc767b6f935e5ada2d96d88e9895388
@@ -145,6 +145,10 @@ class Hour
145
145
  end
146
146
 
147
147
  def -(other)
148
+ if other.to_decimal > self.to_decimal
149
+ raise ArgumentError, "Negative hours not supported"
150
+ end
151
+
148
152
  hours = @h - other.h - (@m - other.m - ((@s - other.s) / 60)) / 60
149
153
  minutes = (@m - other.m - ((@s - other.s) / 60)) % 60
150
154
 
@@ -159,6 +163,11 @@ class Hour
159
163
  self.class.new(hours, minutes, seconds)
160
164
  end
161
165
 
166
+ def *(integer)
167
+ raise ArgumentError, "must be an integer" unless integer.integer?
168
+ self.class.from(seconds: (@h * integer * 3600) + (@m * integer * 60) + (@s * integer))
169
+ end
170
+
162
171
  # Returns a decorator providing convenience methods for working with hours.
163
172
  #
164
173
  # Hour.new(1, 25).hours.round # => 1
@@ -1,23 +1,23 @@
1
- require "hour"
2
- require "coveralls"
1
+ require 'hour'
2
+ require 'coveralls'
3
3
 
4
4
  Coveralls.wear!
5
5
 
6
6
  describe Hour do
7
- describe ".parse" do
7
+ describe '.parse' do
8
8
  pending "implement me" #do
9
9
  # TODO
10
- # p Hour.parse("1:02:30")
10
+ # p Hour.parse('1:02:30')
11
11
  #end
12
12
  end
13
13
 
14
- describe ".now" do
14
+ describe '.now' do
15
15
  pending "implement me" #do
16
16
  # TODO
17
17
  #end
18
18
  end
19
19
 
20
- describe "#to_s" do
20
+ describe '#to_s' do
21
21
  it "pads minutes and seconds with zeros" do
22
22
  hour = Hour.new(1, 9, 5)
23
23
  expect(hour.to_s).to eql('1:09:05')
@@ -41,7 +41,7 @@ describe Hour do
41
41
  end
42
42
  end
43
43
 
44
- describe "#+" do
44
+ describe '#+' do
45
45
  it "returns a new Hour instance returning the total time of the two hour instances" do
46
46
  hour = Hour.new(m: 25, s: 10) + Hour.new(h: 1)
47
47
  expect(hour.hours.value).to eq(1)
@@ -50,8 +50,31 @@ describe Hour do
50
50
  end
51
51
  end
52
52
 
53
- describe ".from" do
54
- context "minutes" do
53
+ describe '#-' do
54
+ it "raises an error if the result would end up negative" do
55
+ expect { Hour.new(m: 55, s: 30) - Hour.new(h: 1) }.to raise_error(ArgumentError)
56
+ end
57
+
58
+ it "returns a new Hour instance returning the difference between the two times" do
59
+ pending "TODO: fix me"
60
+ hour = Hour.new(h: 1, m: 20) - Hour.new(m: 55)
61
+ expect(hour.hours.value).to eql(1)
62
+ expect(hour.minutes.value).to eql(15)
63
+ expect(hour.seconds.value).to eql(0)
64
+ end
65
+ end
66
+
67
+ describe '#*' do
68
+ it "returns a new Hour instance returning the total time of the two hour instances" do
69
+ hour = Hour.new(m: 55, s: 10) * 3
70
+ expect(hour.hours.value).to eq(2)
71
+ expect(hour.minutes.value).to eq(45)
72
+ expect(hour.seconds.value).to eq(30)
73
+ end
74
+ end
75
+
76
+ describe '.from' do
77
+ context 'minutes' do
55
78
  it "returns a new Hour instance" do
56
79
  hour = Hour.from(minutes: 85)
57
80
  expect(hour.hours.value).to eq(1)
@@ -60,7 +83,7 @@ describe Hour do
60
83
  end
61
84
  end
62
85
 
63
- context "seconds" do
86
+ context 'seconds' do
64
87
  it "returns a new Hour instance" do
65
88
  hour = Hour.from(seconds: 2 * 60 * 60 + 25 * 60 + 5)
66
89
  expect(hour.hours.value).to eq(2)
@@ -70,15 +93,15 @@ describe Hour do
70
93
  end
71
94
  end
72
95
 
73
- describe "#hours" do
74
- describe "#value" do
96
+ describe '#hours' do
97
+ describe '#value' do
75
98
  it "returns the exact hour value" do
76
99
  expect(Hour.new(1, 10).hours.value).to eq(1)
77
100
  expect(Hour.new(1, 59).hours.value).to eq(1)
78
101
  end
79
102
  end
80
103
 
81
- describe "#round" do
104
+ describe '#round' do
82
105
  it "returns the rounded hour" do
83
106
  expect(Hour.new(1, 10).hours.round).to eq(1)
84
107
  expect(Hour.new(1, 29, 59).hours.round).to eq(1)
@@ -88,40 +111,40 @@ describe Hour do
88
111
  end
89
112
  end
90
113
 
91
- describe "#minutes" do
92
- describe "#value" do
114
+ describe '#minutes' do
115
+ describe '#value' do
93
116
  it "returns the exact minute value" do
94
117
  expect(Hour.new(1, 25, 52).minutes.value).to eq(25)
95
118
  end
96
119
  end
97
120
 
98
- describe "#round" do
121
+ describe '#round' do
99
122
  it "returns the rounded minutes" do
100
123
  expect(Hour.new(1, 25, 52).minutes.round).to eq(26)
101
124
  end
102
125
  end
103
126
 
104
- describe "#total" do
127
+ describe '#total' do
105
128
  it "returns the total number of minutes" do
106
129
  expect(Hour.new(1, 25, 52).minutes.total).to eq(85)
107
130
  end
108
131
  end
109
132
 
110
- describe "#round_total" do
133
+ describe '#round_total' do
111
134
  it "returns the rounded total number of minutes" do
112
135
  expect(Hour.new(1, 25, 52).minutes.round_total).to eq(86)
113
136
  end
114
137
  end
115
138
  end
116
139
 
117
- describe "#seconds" do
118
- describe "#value" do
140
+ describe '#seconds' do
141
+ describe '#value' do
119
142
  it "returns the exact second value" do
120
143
  expect(Hour.new(m: 1, s: 25).seconds.value).to eq(25)
121
144
  end
122
145
  end
123
146
 
124
- describe "#total" do
147
+ describe '#total' do
125
148
  it "returns the exact total number of seconds" do
126
149
  expect(Hour.new(m: 1, s: 25).seconds.total).to eq(85)
127
150
  expect(Hour.new(1, 10, 25).seconds.total).to eq(1 * 60 * 60 + 10 * 60 + 25)
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hour-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James C Russell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-21 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: "."
14
- email: james@101ideas.cz
13
+ description: Library for handling hour arithmetics. such as addition, multiplication,
14
+ conversion to decimal etc.
15
+ email: james+rubygems@botanicus.me
15
16
  executables: []
16
17
  extensions: []
17
18
  extra_rdoc_files: []
@@ -42,5 +43,5 @@ requirements: []
42
43
  rubygems_version: 3.0.3
43
44
  signing_key:
44
45
  specification_version: 4
45
- summary: ''
46
+ summary: Library for handling hour arithmetics.
46
47
  test_files: []