work_hours_calculator 0.1.3 → 0.1.4

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: e0baff1626d9ecb657e068cc2363518939f510b3980d77ba15f011381cbad270
4
- data.tar.gz: 8221eaa1ec3c962962731868b9a980e852159e5954ef9c7fb49576d91b17f37f
3
+ metadata.gz: 2d7296652efae4aa80651a3887ac25154161d71a72f9535f527934c4d760aa7f
4
+ data.tar.gz: 8a469a806bc11f9c01e9adcc4877016e52e223086b94a2d80f3d4f2305ec0df3
5
5
  SHA512:
6
- metadata.gz: 8fb1f9bb9bc8f161456a068fd5e4ffe2342bfadfa0e9c39013c3718670123431356ab9ebb7d1ffd1c3e9d3b8bf41a78826be4ebdab0865f89b0f841bd3362ebf
7
- data.tar.gz: 5a2651adb63bb57b03855ab2e41274cd32acd649616232fe122d86d4487054e86ee9906992895186cbcee10aae6d8b550b9cad3a40620628167fe3ae796eaf57
6
+ metadata.gz: 8ce0a70e34578886ed9db9cc90f2106a79a600f82513ba2ffc6ebd3313f37b88c0d7977162379e8b31dbf29f4e50d49d7d7f9813a05cca440e2822bc748ae748
7
+ data.tar.gz: cb636ced3ad71141105816df20d7a1e902129750c29d7d0d58ccf2f6b99af120db63f941d6a600f912d6b69d0bb99f7d67b6951945667ed43bf02be0b0c41aab
@@ -6,6 +6,8 @@ require "optparse"
6
6
  module WorkHoursCalculator
7
7
  class Error < StandardError; end
8
8
 
9
+ class InvalidTimeError < StandardError; end
10
+
9
11
  # This class takes a work_start, work_end, and breaks as input,
10
12
  # and calculates the total work hours, total break hours, and net work hours.
11
13
  class Calculate
@@ -13,11 +15,20 @@ module WorkHoursCalculator
13
15
  @work_start_time = parse_time(work_start)
14
16
  @work_end_time = parse_time(work_end)
15
17
  @breaks = breaks.map { |start, end_time| [parse_time(start), parse_time(end_time)] }
18
+
19
+ raise InvalidTimeError, "Work start time is invalid" if @work_start_time.nil?
20
+ raise InvalidTimeError, "Work end time is invalid" if @work_end_time.nil?
16
21
  end
17
22
 
18
23
  def execute
19
24
  total_work_time = @work_end_time - @work_start_time
20
- total_break_time = @breaks.reduce(0) { |sum, (start, end_time)| sum + (end_time - start) }
25
+ total_break_time = @breaks.reduce(0) do |sum, (start, end_time)|
26
+ if start && end_time
27
+ sum + (end_time - start)
28
+ else
29
+ sum
30
+ end
31
+ end
21
32
  net_work_time = total_work_time - total_break_time
22
33
 
23
34
  {
@@ -32,6 +43,8 @@ module WorkHoursCalculator
32
43
 
33
44
  def parse_time(time_str)
34
45
  Time.parse(time_str)
46
+ rescue ArgumentError, TypeError
47
+ nil
35
48
  end
36
49
 
37
50
  def to_hours(seconds)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkHoursCalculator
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_hours_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerda Decio
@@ -76,7 +76,7 @@ licenses:
76
76
  metadata:
77
77
  allowed_push_host: https://rubygems.org
78
78
  homepage_uri: https://github.com/gerdadecio/work-hours-calculator-ruby
79
- source_code_uri: https://github.com/gerdadecio/work-hours-calculator-ruby
79
+ documentation_uri: https://github.com/gerdadecio/work-hours-calculator-ruby
80
80
  bug_tracker_uri: https://github.com/gerdadecio/work-hours-calculator-ruby/issues
81
81
  changelog_uri: https://github.com/gerdadecio/work-hours-calculator-ruby/blob/main/CHANGELOG.md
82
82
  post_install_message: