duration-formatter 1.1.1 → 1.2.0
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 +4 -4
- data/.gitignore +4 -1
- data/.travis.yml +2 -4
- data/README.md +9 -17
- data/duration-formatter.gemspec +4 -5
- data/lib/duration_formatter/version.rb +1 -1
- data/lib/formatted_duration.rb +7 -7
- data/test/lib/formatted_duration_test.rb +3 -3
- metadata +7 -8
- data/Gemfile.lock +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e09efaf9e97304ec46ee26493ab16e2f7d6c55
|
4
|
+
data.tar.gz: 1b4d5d142340debdb646d1b135db0b66ebcb14b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c3a9b63bf0fba1aa0f01a85b3131d71ac189a60eae37eb1e9b45dd3d647199f8a4ae104b192c01bff11f05fe3066fb705ed484e3a4fbe3cc07aa429540d12f
|
7
|
+
data.tar.gz: c1ee518358905e5e5b25d6131b5e197e7b88543c3f3f84d1139cfd682fc98d5e61f13494fac8834a3ee1a0e7f76307360f8afbee6c43fb73f0884eede8a9da0a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,17 +2,22 @@
|
|
2
2
|
|
3
3
|
A simple gem to parse minutes into a readable format using [ruby-duration](https://github.com/peleteiro/ruby-duration).
|
4
4
|
|
5
|
-
[](http://rubygems.org/gems/duration-formatter)
|
6
|
+
[](https://travis-ci.org/richardvenneman/duration-formatter)
|
7
|
+
[](https://codeclimate.com/github/richardvenneman/duration-formatter)
|
8
|
+
[](https://codeclimate.com/github/richardvenneman/duration-formatter/coverage)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
12
|
+
This library is tested with the following Rubies: 2.2.5, 2.3.1.
|
13
|
+
|
9
14
|
Add it to your Gemfile with:
|
10
15
|
|
11
16
|
```ruby
|
12
17
|
gem 'duration-formatter'
|
13
18
|
```
|
14
19
|
|
15
|
-
Run the `bundle install` in your terminal
|
20
|
+
Run the `bundle install` command in your terminal to install it.
|
16
21
|
|
17
22
|
## Usage
|
18
23
|
|
@@ -41,19 +46,6 @@ FormattedDuration.new(1440, :hours).format # => 24 hours
|
|
41
46
|
FormattedDuration.new(80, :minutes).format # => 80 minutes
|
42
47
|
```
|
43
48
|
|
44
|
-
##
|
45
|
-
|
46
|
-
This gem is a work-in-progress. Planned features:
|
47
|
-
|
48
|
-
1. Seconds support
|
49
|
-
2. Support “half” units, e.g. 90 minutes becomes 1½ hours
|
50
|
-
|
51
|
-
## Contributing
|
52
|
-
|
53
|
-
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
49
|
+
## License
|
54
50
|
|
55
|
-
|
56
|
-
- Fix bugs and submit pull requests
|
57
|
-
- Write, clarify, or fix documentation
|
58
|
-
- Suggest or add new features
|
59
|
-
- Write missing tests
|
51
|
+
This library is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/duration-formatter.gemspec
CHANGED
@@ -3,7 +3,8 @@ require './lib/duration_formatter/version'
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'duration-formatter'
|
5
5
|
s.version = DurationFormatter::VERSION
|
6
|
-
s.
|
6
|
+
s.license = 'MIT'
|
7
|
+
s.authors = ['Richard Venneman']
|
7
8
|
s.email = 'richardvenneman@me.com'
|
8
9
|
s.homepage =
|
9
10
|
'https://github.com/richardvenneman/duration-formatter'
|
@@ -11,15 +12,13 @@ Gem::Specification.new do |s|
|
|
11
12
|
s.description = 'A simple gem to parse minutes into a readable format using
|
12
13
|
ruby-duration.'
|
13
14
|
|
14
|
-
s.license = 'MIT'
|
15
|
-
|
16
15
|
s.files = `git ls-files`.split("\n")
|
17
16
|
s.test_files = Dir['test/**/*']
|
18
17
|
|
19
18
|
s.add_dependency 'ruby-duration', '~> 3.2'
|
20
19
|
|
21
|
-
s.add_development_dependency 'rake', '~>
|
22
|
-
s.add_development_dependency 'guard', '~> 2.
|
20
|
+
s.add_development_dependency 'rake', '~> 11.1'
|
21
|
+
s.add_development_dependency 'guard', '~> 2.13'
|
23
22
|
s.add_development_dependency 'guard-minitest', '~> 2.4'
|
24
23
|
s.add_development_dependency 'simplecov', '~> 0.9'
|
25
24
|
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
data/lib/formatted_duration.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'ruby-duration'
|
2
2
|
|
3
3
|
class FormattedDuration
|
4
|
-
CONSTRAINTS = [:minutes, :hours, :days, :weeks]
|
5
|
-
FORMATS = { weeks: '%w %~w', days: '%tdu', hours: '%thu', minutes: '%tmu' }
|
6
|
-
BARE_FORMATS = { days: '%d %~d', hours: '%h %~h', minutes: '%m %~m' }
|
7
|
-
BARE = { days: 7, hours: 24, minutes: 60 }
|
4
|
+
CONSTRAINTS = [:minutes, :hours, :days, :weeks].freeze
|
5
|
+
FORMATS = { weeks: '%w %~w', days: '%tdu', hours: '%thu', minutes: '%tmu' }.freeze
|
6
|
+
BARE_FORMATS = { days: '%d %~d', hours: '%h %~h', minutes: '%m %~m' }.freeze
|
7
|
+
BARE = { days: 7, hours: 24, minutes: 60 }.freeze
|
8
8
|
|
9
9
|
def initialize(minutes, constraint = :weeks)
|
10
10
|
@constraint = CONSTRAINTS.index(constraint)
|
@@ -16,7 +16,7 @@ class FormattedDuration
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def format
|
19
|
-
append(:weeks, @weeks, '%w %~w') if @weeks
|
19
|
+
append(:weeks, @weeks, '%w %~w') if @weeks.positive? && @constraint > 2
|
20
20
|
add(:days, @days, 2)
|
21
21
|
add(:hours, @hours, 1)
|
22
22
|
add(:minutes, @minutes, 0)
|
@@ -34,9 +34,9 @@ class FormattedDuration
|
|
34
34
|
def add(unit, value, constraint)
|
35
35
|
bare = value % BARE[unit]
|
36
36
|
|
37
|
-
if value
|
37
|
+
if value.positive? && @constraint == constraint
|
38
38
|
append(unit, value, FORMATS[unit])
|
39
|
-
elsif bare
|
39
|
+
elsif bare.positive? && @constraint > constraint - 1
|
40
40
|
append(unit, bare, BARE_FORMATS[unit])
|
41
41
|
end
|
42
42
|
end
|
@@ -6,7 +6,7 @@ class FormattedDurationTest < Minitest::Test
|
|
6
6
|
|
7
7
|
def test_weeks_only_duration
|
8
8
|
text = '1 week'
|
9
|
-
output = FormattedDuration.new(
|
9
|
+
output = FormattedDuration.new(100_80).format
|
10
10
|
|
11
11
|
assert_equal text, output
|
12
12
|
end
|
@@ -36,7 +36,7 @@ class FormattedDurationTest < Minitest::Test
|
|
36
36
|
|
37
37
|
def test_weeks_and_days_duration
|
38
38
|
text = '1 week, 4 days'
|
39
|
-
output = FormattedDuration.new(
|
39
|
+
output = FormattedDuration.new(158_40).format
|
40
40
|
|
41
41
|
assert_equal text, output
|
42
42
|
end
|
@@ -59,7 +59,7 @@ class FormattedDurationTest < Minitest::Test
|
|
59
59
|
|
60
60
|
def test_days_constraint
|
61
61
|
text = '8 days'
|
62
|
-
output = FormattedDuration.new(
|
62
|
+
output = FormattedDuration.new(115_20, :days).format
|
63
63
|
|
64
64
|
assert_equal text, output
|
65
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duration-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-duration
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '11.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: '
|
40
|
+
version: '11.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.13'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
54
|
+
version: '2.13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- ".gitignore"
|
106
106
|
- ".travis.yml"
|
107
107
|
- Gemfile
|
108
|
-
- Gemfile.lock
|
109
108
|
- Guardfile
|
110
109
|
- README.md
|
111
110
|
- Rakefile
|
@@ -135,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
134
|
version: '0'
|
136
135
|
requirements: []
|
137
136
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.5.1
|
139
138
|
signing_key:
|
140
139
|
specification_version: 4
|
141
140
|
summary: Formatter for ruby-duration
|
data/Gemfile.lock
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
duration-formatter (1.1.1)
|
5
|
-
ruby-duration (~> 3.2)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (4.2.3)
|
11
|
-
i18n (~> 0.7)
|
12
|
-
json (~> 1.7, >= 1.7.7)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
-
tzinfo (~> 1.1)
|
16
|
-
codeclimate-test-reporter (0.4.7)
|
17
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
18
|
-
coderay (1.1.0)
|
19
|
-
docile (1.1.5)
|
20
|
-
ffi (1.9.10)
|
21
|
-
formatador (0.2.5)
|
22
|
-
guard (2.12.7)
|
23
|
-
formatador (>= 0.2.4)
|
24
|
-
listen (>= 2.7, <= 4.0)
|
25
|
-
lumberjack (~> 1.0)
|
26
|
-
nenv (~> 0.1)
|
27
|
-
notiffany (~> 0.0)
|
28
|
-
pry (>= 0.9.12)
|
29
|
-
shellany (~> 0.0)
|
30
|
-
thor (>= 0.18.1)
|
31
|
-
guard-compat (1.2.1)
|
32
|
-
guard-minitest (2.4.4)
|
33
|
-
guard-compat (~> 1.2)
|
34
|
-
minitest (>= 3.0)
|
35
|
-
i18n (0.7.0)
|
36
|
-
iso8601 (0.8.6)
|
37
|
-
json (1.8.3)
|
38
|
-
listen (3.0.1)
|
39
|
-
rb-fsevent (>= 0.9.3)
|
40
|
-
rb-inotify (>= 0.9)
|
41
|
-
lumberjack (1.0.9)
|
42
|
-
method_source (0.8.2)
|
43
|
-
minitest (5.7.0)
|
44
|
-
nenv (0.2.0)
|
45
|
-
notiffany (0.0.6)
|
46
|
-
nenv (~> 0.1)
|
47
|
-
shellany (~> 0.0)
|
48
|
-
pry (0.10.1)
|
49
|
-
coderay (~> 1.1.0)
|
50
|
-
method_source (~> 0.8.1)
|
51
|
-
slop (~> 3.4)
|
52
|
-
rake (10.4.2)
|
53
|
-
rb-fsevent (0.9.5)
|
54
|
-
rb-inotify (0.9.5)
|
55
|
-
ffi (>= 0.5.0)
|
56
|
-
ruby-duration (3.2.1)
|
57
|
-
activesupport (>= 3.0.0)
|
58
|
-
i18n
|
59
|
-
iso8601
|
60
|
-
shellany (0.0.1)
|
61
|
-
simplecov (0.10.0)
|
62
|
-
docile (~> 1.1.0)
|
63
|
-
json (~> 1.8)
|
64
|
-
simplecov-html (~> 0.10.0)
|
65
|
-
simplecov-html (0.10.0)
|
66
|
-
slop (3.6.0)
|
67
|
-
thor (0.19.1)
|
68
|
-
thread_safe (0.3.5)
|
69
|
-
tzinfo (1.2.2)
|
70
|
-
thread_safe (~> 0.1)
|
71
|
-
|
72
|
-
PLATFORMS
|
73
|
-
ruby
|
74
|
-
|
75
|
-
DEPENDENCIES
|
76
|
-
codeclimate-test-reporter (~> 0.4)
|
77
|
-
duration-formatter!
|
78
|
-
guard (~> 2.12)
|
79
|
-
guard-minitest (~> 2.4)
|
80
|
-
rake (~> 10.4)
|
81
|
-
simplecov (~> 0.9)
|
82
|
-
|
83
|
-
BUNDLED WITH
|
84
|
-
1.10.5
|