tempus 1.0.1 → 1.0.2

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: 2001b2e89f2be1909675a61ef595fcb3fa103b575c90cdcf1186961bac14077e
4
- data.tar.gz: 3952d416260d86f7ef8c2fadc77077e6c27f937462625bcca5b177e09dd01499
3
+ metadata.gz: 3a87552c97756fad29ee94fd1f92a21f9fd1cc3f5992ea0cff9cc3d7c142f901
4
+ data.tar.gz: cbb553cd446f654d7337876d0838fe8cd0349fc4928852a181f0c706c2d3b8e9
5
5
  SHA512:
6
- metadata.gz: fed0de79e4abb9a77b68606052c5011a16dd5dadf7abf4782b61ac225dbdbddca39b8d39f22d139c515c48013a617b160012e89eaba9f3f8a95e75848e89cde3
7
- data.tar.gz: 5d4f7b6952b668b061ffb83451f721d97809810089b0b4c0748060a2cdde89c7729e0badc2d31ab0eb7ed6b4088cbcda0a9a80dde56baec837bffb17289d8627
6
+ metadata.gz: dc27715ac6f21750df4ec9b04a80411428e2e003b16c1e72b2e35c15f69692963bc5f145fe1b64e4d6020643a6ecf756e97b7ce5fa54867ea2a37ea64708180c
7
+ data.tar.gz: 4793c0892203ec2ded2bd084c412ec9b3c325ed35160a1bff251aa6c1c431def8c8e83a7cb103e0bd32478f5f263fa92a11c00aefb29be1e79c3f00b4e0d20c3
data/.hound.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  rubocop:
2
2
  config_file: .rubocop.yml
3
- version: 0.72.0
3
+ version: 0.80.0
@@ -1,3 +1,8 @@
1
1
  Metrics/BlockLength:
2
2
  Exclude:
3
+ - 'tempus.gemspec'
3
4
  - 'spec/**/*.rb'
5
+
6
+ Layout/LineLength:
7
+ Exclude:
8
+ - 'tempus.gemspec'
@@ -1,8 +1,7 @@
1
1
  ---
2
- sudo: false
3
2
  language: ruby
4
3
  cache: bundler
5
4
  rvm:
6
5
  - 2.5.0
7
- - 2.6.3
8
- before_install: gem install bundler -v 1.17.3
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.1.4
@@ -68,7 +68,7 @@ members of the project's leadership.
68
68
  ## Attribution
69
69
 
70
70
  This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
72
 
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tempus (1.0.1)
4
+ tempus (1.0.2)
5
5
  activesupport (> 5)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (6.0.0)
10
+ activesupport (6.0.2.1)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 0.7, < 2)
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
- zeitwerk (~> 2.1, >= 2.1.8)
16
- concurrent-ruby (1.1.5)
15
+ zeitwerk (~> 2.2)
16
+ concurrent-ruby (1.1.6)
17
17
  coveralls (0.8.23)
18
18
  json (>= 1.8, < 3)
19
19
  simplecov (~> 0.16.1)
@@ -22,48 +22,50 @@ GEM
22
22
  tins (~> 1.6)
23
23
  diff-lcs (1.3)
24
24
  docile (1.3.2)
25
- i18n (1.6.0)
25
+ i18n (1.8.2)
26
26
  concurrent-ruby (~> 1.0)
27
- json (2.2.0)
28
- minitest (5.11.3)
29
- rake (10.5.0)
30
- rspec (3.8.0)
31
- rspec-core (~> 3.8.0)
32
- rspec-expectations (~> 3.8.0)
33
- rspec-mocks (~> 3.8.0)
34
- rspec-core (3.8.2)
35
- rspec-support (~> 3.8.0)
36
- rspec-expectations (3.8.4)
27
+ json (2.3.0)
28
+ minitest (5.14.0)
29
+ rake (13.0.1)
30
+ rspec (3.9.0)
31
+ rspec-core (~> 3.9.0)
32
+ rspec-expectations (~> 3.9.0)
33
+ rspec-mocks (~> 3.9.0)
34
+ rspec-core (3.9.1)
35
+ rspec-support (~> 3.9.1)
36
+ rspec-expectations (3.9.1)
37
37
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.8.0)
39
- rspec-mocks (3.8.1)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-mocks (3.9.1)
40
40
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.8.0)
42
- rspec-support (3.8.2)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-support (3.9.2)
43
43
  simplecov (0.16.1)
44
44
  docile (~> 1.1)
45
45
  json (>= 1.8, < 3)
46
46
  simplecov-html (~> 0.10.0)
47
47
  simplecov-html (0.10.2)
48
+ sync (0.5.0)
48
49
  term-ansicolor (1.7.1)
49
50
  tins (~> 1.0)
50
- thor (0.20.3)
51
+ thor (1.0.1)
51
52
  thread_safe (0.3.6)
52
- tins (1.21.1)
53
- tzinfo (1.2.5)
53
+ tins (1.24.1)
54
+ sync
55
+ tzinfo (1.2.6)
54
56
  thread_safe (~> 0.1)
55
- zeitwerk (2.1.9)
57
+ zeitwerk (2.3.0)
56
58
 
57
59
  PLATFORMS
58
60
  ruby
59
61
 
60
62
  DEPENDENCIES
61
- bundler (~> 1.17)
63
+ bundler (~> 2.1)
62
64
  coveralls (~> 0.8)
63
- rake (~> 10.0)
64
- rspec (~> 3.0)
65
- simplecov (~> 0.1)
65
+ rake (~> 13.0)
66
+ rspec (~> 3.9)
67
+ simplecov (~> 0.9)
66
68
  tempus!
67
69
 
68
70
  BUNDLED WITH
69
- 1.17.3
71
+ 2.1.4
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem 'tempus'
16
16
 
17
17
  And then execute:
18
18
 
19
- $ bundle
19
+ $ bundle install
20
20
 
21
21
  Or install it yourself as:
22
22
 
@@ -61,7 +61,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
61
61
 
62
62
  ## Contributing
63
63
 
64
- Bug reports and pull requests are welcome on GitHub at https://github.com/dannnylo/tempus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dannnylo/tempus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dannnylo/tempus/blob/master/CODE_OF_CONDUCT.md).
65
+
65
66
 
66
67
  ## License
67
68
 
@@ -69,4 +70,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
69
70
 
70
71
  ## Code of Conduct
71
72
 
72
- Everyone interacting in the Tempus projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dannnylo/tempus/blob/master/CODE_OF_CONDUCT.md).
73
+ Everyone interacting in the Tempus project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dannnylo/tempus/blob/master/CODE_OF_CONDUCT.md).
@@ -4,6 +4,7 @@ require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
 
6
6
  require 'tempus/version'
7
+ require 'tempus/parser'
7
8
  require 'tempus/tempus_helper'
8
9
 
9
10
  # Class to manipulate efficiently time
@@ -16,39 +17,20 @@ class Tempus
16
17
  HOURS_REGEX = /(\%h|\%hh|\%H|\%HH)/.freeze
17
18
  MINUTES_REGEX = /(\%m|\%mm|\%M|\%MM)/.freeze
18
19
  SECONDS_REGEX = /(\%s|\%ss|\%S|\%SS)/.freeze
20
+ OPERATIONS = %i[+ - * /].freeze
19
21
 
20
22
  attr_reader :data
21
23
 
22
24
  delegate :to_i, :to_f, :negative?, :positive?, to: :data
23
25
 
24
26
  def initialize(value = 0, only_hours = true)
25
- @data = transform(value, only_hours)
26
- end
27
-
28
- def set(value, only_hours = true)
29
- @data = transform(value, only_hours)
30
- end
27
+ @parser = Parser.new(only_hours)
31
28
 
32
- def transform(value, only_hours = true)
33
- return from_string(value).to_f if value.is_a?(String)
34
- return from_time(value, only_hours).to_f if value.is_a?(Time)
35
-
36
- value.to_f
29
+ set(value)
37
30
  end
38
31
 
39
- def from_string(value)
40
- str = value.to_s.split(':')
41
- value = 0
42
-
43
- %i[hours minutes seconds].each_with_index do |m, i|
44
- value += str.at(i).to_i.abs.send(m.to_s)
45
- end
46
-
47
- str.to_s.include?('-') ? value * -1 : value
48
- end
49
-
50
- def from_time(value, only_hours = true)
51
- (only_hours ? value - value.beginning_of_day : value).to_f
32
+ def set(value)
33
+ @data = @parser.parse(value)
52
34
  end
53
35
 
54
36
  # Format the duration to para HH:MM:SS .
@@ -78,7 +60,7 @@ class Tempus
78
60
  alias to_string to_s
79
61
 
80
62
  def format_number_abs(number)
81
- format('%02d', number.to_i.abs)
63
+ format('%02<number>d', number: number.to_i.abs)
82
64
  end
83
65
 
84
66
  def seconds
@@ -111,26 +93,6 @@ class Tempus
111
93
 
112
94
  alias to_xls_time value_in_days
113
95
 
114
- # Sum values of instance
115
- def +(other)
116
- Tempus.new(data + transform(other))
117
- end
118
-
119
- # Subtract values of instance
120
- def -(other)
121
- Tempus.new(data - transform(other))
122
- end
123
-
124
- # Multiplication values of instance
125
- def *(other)
126
- Tempus.new(data * transform(other))
127
- end
128
-
129
- # Division values of instance
130
- def /(other)
131
- Tempus.new(data / transform(other))
132
- end
133
-
134
96
  def human
135
97
  [
136
98
  ('menos' if negative?),
@@ -150,4 +112,14 @@ class Tempus
150
112
 
151
113
  data == other.data
152
114
  end
115
+
116
+ def method_missing(method_name, *args, &block)
117
+ return super unless OPERATIONS.include?(method_name)
118
+
119
+ @data.send(method_name, @parser.parse(args.first)).to_tempus
120
+ end
121
+
122
+ def respond_to_missing?(method_name, include_private = false)
123
+ OPERATIONS.include?(method_name.to_sym) || super
124
+ end
153
125
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Parser others types to value
4
+ class Parser
5
+ def initialize(only_hours = true)
6
+ @only_hours = only_hours
7
+ end
8
+
9
+ def parse(value)
10
+ @value = value
11
+
12
+ if @value.is_a?(String)
13
+ from_string.to_f
14
+ elsif @value.is_a?(Time)
15
+ from_time.to_f
16
+ else
17
+ @value.to_f
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def from_time
24
+ return @value.to_f unless @only_hours
25
+
26
+ (@value - @value.beginning_of_day).to_f
27
+ end
28
+
29
+ def from_string
30
+ str = @value.to_s.split(':')
31
+ value = 0
32
+
33
+ %i[hours minutes seconds].each_with_index do |m, i|
34
+ value += str.at(i).to_i.abs.send(m.to_s)
35
+ end
36
+
37
+ str.to_s.include?('-') ? value * -1 : value
38
+ end
39
+ end
@@ -7,4 +7,4 @@ module TempusHelper
7
7
  end
8
8
  end
9
9
 
10
- Object.send(:include, TempusHelper)
10
+ Object.include(TempusHelper)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Tempus
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'tempus/version'
3
+ require_relative 'lib/tempus/version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'tempus'
@@ -18,21 +16,21 @@ Gem::Specification.new do |spec|
18
16
 
19
17
  spec.homepage = 'https://github.com/dannnylo/tempus'
20
18
  spec.license = 'MIT'
19
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
21
20
 
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem
24
- # that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- files = `git ls-files -z`.split("\x0")
27
- files.reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
26
  end
29
27
  spec.bindir = 'exe'
30
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ['lib', 'lib/tempus']
29
+ spec.require_paths = ['lib']
32
30
  spec.add_runtime_dependency 'activesupport', '> 5'
33
- spec.add_development_dependency 'bundler', '~> 1.17'
31
+ spec.add_development_dependency 'bundler', '~> 2.1'
34
32
  spec.add_development_dependency 'coveralls', '~> 0.8'
35
- spec.add_development_dependency 'rake', '~> 10.0'
36
- spec.add_development_dependency 'rspec', '~> 3.0'
37
- spec.add_development_dependency 'simplecov', '~> 0.1'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.9'
35
+ spec.add_development_dependency 'simplecov', '~> 0.9'
38
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Jeremias da Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.17'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.17'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '3.9'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '3.9'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.1'
89
+ version: '0.9'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.1'
96
+ version: '0.9'
97
97
  description: |2
98
98
  Gem to efficiently manipulate the time.
99
99
  Adding, subtracting and converting more than 24 hours easy.'
@@ -118,23 +118,25 @@ files:
118
118
  - bin/console
119
119
  - bin/setup
120
120
  - lib/tempus.rb
121
+ - lib/tempus/parser.rb
121
122
  - lib/tempus/tempus_helper.rb
122
123
  - lib/tempus/version.rb
123
124
  - tempus.gemspec
124
125
  homepage: https://github.com/dannnylo/tempus
125
126
  licenses:
126
127
  - MIT
127
- metadata: {}
128
+ metadata:
129
+ homepage_uri: https://github.com/dannnylo/tempus
130
+ source_code_uri: https://github.com/dannnylo/tempus
128
131
  post_install_message:
129
132
  rdoc_options: []
130
133
  require_paths:
131
134
  - lib
132
- - lib/tempus
133
135
  required_ruby_version: !ruby/object:Gem::Requirement
134
136
  requirements:
135
137
  - - ">="
136
138
  - !ruby/object:Gem::Version
137
- version: '0'
139
+ version: 2.3.0
138
140
  required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  requirements:
140
142
  - - ">="