forty_time 0.0.3 → 0.0.4

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: '071931c41302088f992b65e139a2096750853345b4a48b85935417626e271945'
4
- data.tar.gz: 694dd460289cfa95d98309ba75fedb002247147e79e8cc85363b7e4c345623a9
3
+ metadata.gz: 78c83da48923ac51635904a0e352188c594e045ee35939aa36789f84891665b3
4
+ data.tar.gz: 8aac8b9f2370591e9399e7b22d0c342d406f89e06ec6ca9e576041bbbd850750
5
5
  SHA512:
6
- metadata.gz: '085e00d9221e77c7c4dbd83343011748f3854348fcf82e752d13519e6fd3c15bf8b9f5e4c26ea110ed2579a3eaf5169d748cdc4aa3e29af31c2bf3f107cb24d0'
7
- data.tar.gz: b57fee25db4755c7d1e304f44fce8929021f698535728a19ff2aefa4e2df1d1bff322cd2f64d3348be145831f1503e9c9c9b7caac386c16a5a3f5d15e8cbfda7
6
+ metadata.gz: fd574595c58d6dece0a7b9f35d8cefe8d28b646c1b1957a6c5101a836140da1e0dd9b213db33ff37fe7853f1ef4d9a29b9bc23faf41a58e95f0be13cd9da132e
7
+ data.tar.gz: 2d5f14df831f55d454fc10b1f9b8cd91c7635c0763013ec4943d64f57a1ff8198223b68bac2f4f734a4e14b1e3047746412075442f50f0d55d0a456da615c1eb
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ Layout/LineLength:
2
+ Exclude:
3
+ - 'forty_time.gemspec'
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - 'spec/**/*'
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/HashEachMethods:
13
+ Enabled: true
14
+
15
+ Style/HashTransformKeys:
16
+ Enabled: true
17
+
18
+ Style/HashTransformValues:
19
+ Enabled: true
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in forty_time.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake"
7
- gem "rspec"
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rubocop'
data/Gemfile.lock CHANGED
@@ -1,13 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- forty_time (0.0.1)
4
+ forty_time (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
9
10
  diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.0.5)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
10
16
  rake (12.3.3)
17
+ rexml (3.2.4)
11
18
  rspec (3.9.0)
12
19
  rspec-core (~> 3.9.0)
13
20
  rspec-expectations (~> 3.9.0)
@@ -21,6 +28,16 @@ GEM
21
28
  diff-lcs (>= 1.2.0, < 2.0)
22
29
  rspec-support (~> 3.9.0)
23
30
  rspec-support (3.9.2)
31
+ rubocop (0.80.1)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ rexml
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 1.7)
39
+ ruby-progressbar (1.10.1)
40
+ unicode-display_width (1.6.1)
24
41
 
25
42
  PLATFORMS
26
43
  ruby
@@ -29,6 +46,7 @@ DEPENDENCIES
29
46
  forty_time!
30
47
  rake
31
48
  rspec
49
+ rubocop
32
50
 
33
51
  BUNDLED WITH
34
52
  2.1.2
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ desc 'Run RuboCop'
8
+ RuboCop::RakeTask.new(:rubocop)
3
9
 
4
10
  RSpec::Core::RakeTask.new(:spec)
5
11
 
6
- task :default => :spec
12
+ task default: %i[rubocop spec]
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "forty_time"
4
+ require 'bundler/setup'
5
+ require 'forty_time'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "forty_time"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/lib/forty_time.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class FortyTime
2
- VERSION = "0.0.3"
4
+ VERSION = '0.0.4'
3
5
 
4
6
  class ParseError < StandardError; end
5
7
 
@@ -9,8 +11,11 @@ class FortyTime
9
11
  can_parse_string = input.is_a?(String) && input.match?(/:/)
10
12
  raise ParseError unless can_parse_string
11
13
 
12
- hours, extra = input.split(":").map(&:to_i)
14
+ hours, extra = input.split(':').map(&:to_i)
13
15
  minutes = hours * 60 + extra
16
+
17
+ minutes *= -1 if input[0] == '-'
18
+
14
19
  new(minutes)
15
20
  end
16
21
 
@@ -20,20 +25,27 @@ class FortyTime
20
25
  @minutes = minutes
21
26
  end
22
27
 
23
- def +(rhs)
24
- result = @minutes + rhs.minutes
28
+ def +(other)
29
+ result = @minutes + other.minutes
25
30
  FortyTime.new(result)
26
31
  end
27
32
 
28
- def -(rhs)
29
- result = @minutes - rhs.minutes
33
+ def -(other)
34
+ result = @minutes - other.minutes
30
35
  FortyTime.new(result)
31
36
  end
32
37
 
33
38
  def to_s
34
- hours = @minutes / 60
35
- extra = @minutes - hours * 60
39
+ hours = (@minutes / 60.0).to_i
40
+ extra = (@minutes - hours * 60.0).to_i
41
+
42
+ if @minutes.negative?
43
+ hours *= -1
44
+ extra *= -1
45
+ hours = "-#{hours}"
46
+ end
47
+
36
48
  extra = "0#{extra}" if extra < 10
37
- [hours, extra].join(":")
49
+ [hours, extra].join(':')
38
50
  end
39
51
  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.3
4
+ version: 0.0.4
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-03-27 00:00:00.000000000 Z
11
+ date: 2020-03-31 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.
@@ -20,6 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - ".gitignore"
22
22
  - ".rspec"
23
+ - ".rubocop.yml"
23
24
  - Gemfile
24
25
  - Gemfile.lock
25
26
  - LICENSE.txt