duration-formatter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +11 -0
- data/Gemfile.lock +13 -3
- data/README.md +56 -0
- data/duration-formatter.gemspec +2 -1
- data/lib/duration_formatter/version.rb +1 -1
- data/lib/formatted_duration.rb +5 -1
- data/test/lib/formatted_duration_test.rb +14 -0
- data/test/test_helper.rb +7 -0
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719df39ecfaa4879706be6e1c4ab68cdb7a9b7df
|
4
|
+
data.tar.gz: 6212e2a572bc0a72cde231bf1aa6db37a543e19f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b73e3c5dfa20f653f594dae622379e892dc59638ae928bfa7f80f02f6d2e661113665c70ebbfe1fe07037b4cc34ce96384b77006c7fce5f0a7f67c135fcc9b5b
|
7
|
+
data.tar.gz: 60734ab1ff638952b4f9e62832cc561085b63a1e91aaf6fc74eaeb580d04b45d46f91034dab7f591eb5bed403065510bb3e38bf83ecd5f6171d5f508c1e3245a
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coverage
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
duration-formatter (0.
|
5
|
-
ruby-duration (
|
4
|
+
duration-formatter (0.1.1)
|
5
|
+
ruby-duration (~> 3.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -13,7 +13,10 @@ GEM
|
|
13
13
|
minitest (~> 5.1)
|
14
14
|
thread_safe (~> 0.3, >= 0.3.4)
|
15
15
|
tzinfo (~> 1.1)
|
16
|
+
codeclimate-test-reporter (0.4.7)
|
17
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
16
18
|
coderay (1.1.0)
|
19
|
+
docile (1.1.5)
|
17
20
|
ffi (1.9.10)
|
18
21
|
formatador (0.2.5)
|
19
22
|
guard (2.12.7)
|
@@ -46,6 +49,7 @@ GEM
|
|
46
49
|
coderay (~> 1.1.0)
|
47
50
|
method_source (~> 0.8.1)
|
48
51
|
slop (~> 3.4)
|
52
|
+
rake (10.4.2)
|
49
53
|
rb-fsevent (0.9.5)
|
50
54
|
rb-inotify (0.9.5)
|
51
55
|
ffi (>= 0.5.0)
|
@@ -54,6 +58,11 @@ GEM
|
|
54
58
|
i18n
|
55
59
|
iso8601
|
56
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)
|
57
66
|
slop (3.6.0)
|
58
67
|
thor (0.19.1)
|
59
68
|
thread_safe (0.3.5)
|
@@ -64,10 +73,11 @@ PLATFORMS
|
|
64
73
|
ruby
|
65
74
|
|
66
75
|
DEPENDENCIES
|
76
|
+
codeclimate-test-reporter (~> 0.4)
|
67
77
|
duration-formatter!
|
68
78
|
guard (~> 2.12)
|
69
79
|
guard-minitest (~> 2.4)
|
70
|
-
|
80
|
+
rake (~> 10.4)
|
71
81
|
|
72
82
|
BUNDLED WITH
|
73
83
|
1.10.3
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#duration-formatter
|
2
|
+
|
3
|
+
A simple gem to parse minutes into a readable format using [ruby-duration](https://github.com/peleteiro/ruby-duration).
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/duration-formatter.svg)](http://badge.fury.io/rb/duration-formatter) [![Code Climate](https://codeclimate.com/github/richardvenneman/duration-formatter/badges/gpa.svg)](https://codeclimate.com/github/richardvenneman/duration-formatter) [![Dependency Status](https://gemnasium.com/richardvenneman/duration-formatter.svg)](https://gemnasium.com/richardvenneman/duration-formatter) [![Test Coverage](https://codeclimate.com/github/richardvenneman/duration-formatter/badges/coverage.svg)](https://codeclimate.com/github/richardvenneman/duration-formatter/coverage) [![Build Status](http://img.shields.io/travis/richardvenneman/duration-formatter.svg)](https://travis-ci.org/richardvenneman/duration-formatter)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add it to your Gemfile with:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'duration-formatter'
|
13
|
+
```
|
14
|
+
|
15
|
+
Run the `bundle install` in your terminal command to install it.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
The gem exposes a class `FormattedDuration` which takes the passed minutes to determine the format. Calling `format` on the instance returns the formatted duration. Examples:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# Full units
|
23
|
+
FormattedDuration.new(10080).format # => 1 week
|
24
|
+
FormattedDuration.new(1440).format # => 1 day
|
25
|
+
FormattedDuration.new(240).format # => 4 hours
|
26
|
+
FormattedDuration.new(20).format # => 20 minutes
|
27
|
+
|
28
|
+
# Composition
|
29
|
+
FormattedDuration.new(15840).format # => 1 week, 4 days
|
30
|
+
FormattedDuration.new(1450).format # => 1 day, 10 minutes
|
31
|
+
FormattedDuration.new(241).format # => 4 hours, 1 minute
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also force a constraint upon the format.
|
35
|
+
|
36
|
+
```
|
37
|
+
FormattedDuration.new(1440, :hours).format # => 24 hours
|
38
|
+
FormattedDuration.new(11520, :days).format # => 15 days
|
39
|
+
```
|
40
|
+
|
41
|
+
## TODO
|
42
|
+
|
43
|
+
This gem is a work-in-progress. Planned features:
|
44
|
+
|
45
|
+
1. Seconds support
|
46
|
+
2. Support “half” units, e.g. 90 minutes becomes 1½ hours
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
51
|
+
|
52
|
+
- Report bugs
|
53
|
+
- Fix bugs and submit pull requests
|
54
|
+
- Write, clarify, or fix documentation
|
55
|
+
- Suggest or add new features
|
56
|
+
- Write missing tests
|
data/duration-formatter.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_dependency 'ruby-duration', '~> 3.2'
|
20
20
|
|
21
|
+
s.add_development_dependency 'rake', '~> 10.4'
|
21
22
|
s.add_development_dependency 'guard', '~> 2.12'
|
22
23
|
s.add_development_dependency 'guard-minitest', '~> 2.4'
|
23
|
-
s.add_development_dependency '
|
24
|
+
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
24
25
|
end
|
data/lib/formatted_duration.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'ruby-duration'
|
2
2
|
|
3
3
|
class FormattedDuration
|
4
|
+
WEEKS_FORMAT = '%w %~w'
|
4
5
|
DAYS_FORMAT = '%d %~d'
|
5
6
|
HOURS_FORMAT = '%h %~h'
|
6
7
|
MINUTES_FORMAT = '%m %~m'
|
@@ -9,13 +10,16 @@ class FormattedDuration
|
|
9
10
|
@minutes = minutes % 60
|
10
11
|
@hours = minutes / 60
|
11
12
|
@days = @hours / 24
|
13
|
+
@weeks = @days / 7
|
12
14
|
end
|
13
15
|
|
14
16
|
def format
|
17
|
+
weekless_days = @days % 7
|
15
18
|
dayless_hours = @hours % 24
|
16
19
|
output = []
|
17
20
|
|
18
|
-
output << Duration.new(
|
21
|
+
output << Duration.new(weeks: @weeks).format(WEEKS_FORMAT) if @weeks != 0
|
22
|
+
output << Duration.new(days: weekless_days).format(DAYS_FORMAT) if weekless_days != 0
|
19
23
|
output << Duration.new(hours: dayless_hours).format(HOURS_FORMAT) if dayless_hours != 0
|
20
24
|
output << Duration.new(minutes: @minutes).format(MINUTES_FORMAT) if @minutes != 0
|
21
25
|
|
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class FormattedDurationTest < Minitest::Test
|
4
|
+
def test_weeks_only_duration
|
5
|
+
text = '1 week'
|
6
|
+
output = FormattedDuration.new(10080).format
|
7
|
+
|
8
|
+
assert_equal text, output
|
9
|
+
end
|
10
|
+
|
4
11
|
def test_days_only_duration
|
5
12
|
text = '1 day'
|
6
13
|
output = FormattedDuration.new(1440).format
|
@@ -22,6 +29,13 @@ class FormattedDurationTest < Minitest::Test
|
|
22
29
|
assert_equal text, output
|
23
30
|
end
|
24
31
|
|
32
|
+
def test_weeks_and_days_duration
|
33
|
+
text = '1 week, 4 days'
|
34
|
+
output = FormattedDuration.new(15840).format
|
35
|
+
|
36
|
+
assert_equal text, output
|
37
|
+
end
|
38
|
+
|
25
39
|
def test_days_and_hours_duration
|
26
40
|
text = '1 day, 4 hours'
|
27
41
|
output = FormattedDuration.new(1680).format
|
data/test/test_helper.rb
CHANGED
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: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-duration
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: guard
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,19 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '2.4'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: codeclimate-test-reporter
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
75
|
+
version: '0.4'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
82
|
+
version: '0.4'
|
69
83
|
description: |-
|
70
84
|
A simple gem to parse minutes into a readable format using
|
71
85
|
ruby-duration.
|
@@ -74,9 +88,12 @@ executables: []
|
|
74
88
|
extensions: []
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
77
93
|
- Gemfile
|
78
94
|
- Gemfile.lock
|
79
95
|
- Guardfile
|
96
|
+
- README.md
|
80
97
|
- Rakefile
|
81
98
|
- duration-formatter.gemspec
|
82
99
|
- lib/duration-formatter.rb
|