duration-formatter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6bb2a65ea8d1aadd85b1018ff0c54d2d6079e6e
4
+ data.tar.gz: 3d5b1dd23611dee4a6d897550bdde6486fce5201
5
+ SHA512:
6
+ metadata.gz: 18ad445e24a43944a7e4326c5a0e2ccf45543ad1f8f14d14ae2c03a606d1eba15c4396f41617adb53a7f4e55f47e9381c1c6270961340b1c6e10330053cde8f5
7
+ data.tar.gz: e444f16be3934bf1c77d831d681f4b99fa8f65a2fb322186f42d54a16b4288763abaf502767d381c52f78586ea8259c9794c0e7036c41737f1424a6463cc1371
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ duration-formatter (0.0.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
+ coderay (1.1.0)
17
+ ffi (1.9.10)
18
+ formatador (0.2.5)
19
+ guard (2.12.7)
20
+ formatador (>= 0.2.4)
21
+ listen (>= 2.7, <= 4.0)
22
+ lumberjack (~> 1.0)
23
+ nenv (~> 0.1)
24
+ notiffany (~> 0.0)
25
+ pry (>= 0.9.12)
26
+ shellany (~> 0.0)
27
+ thor (>= 0.18.1)
28
+ guard-compat (1.2.1)
29
+ guard-minitest (2.4.4)
30
+ guard-compat (~> 1.2)
31
+ minitest (>= 3.0)
32
+ i18n (0.7.0)
33
+ iso8601 (0.8.6)
34
+ json (1.8.3)
35
+ listen (3.0.1)
36
+ rb-fsevent (>= 0.9.3)
37
+ rb-inotify (>= 0.9)
38
+ lumberjack (1.0.9)
39
+ method_source (0.8.2)
40
+ minitest (5.7.0)
41
+ nenv (0.2.0)
42
+ notiffany (0.0.6)
43
+ nenv (~> 0.1)
44
+ shellany (~> 0.0)
45
+ pry (0.10.1)
46
+ coderay (~> 1.1.0)
47
+ method_source (~> 0.8.1)
48
+ slop (~> 3.4)
49
+ rb-fsevent (0.9.5)
50
+ rb-inotify (0.9.5)
51
+ ffi (>= 0.5.0)
52
+ ruby-duration (3.2.1)
53
+ activesupport (>= 3.0.0)
54
+ i18n
55
+ iso8601
56
+ shellany (0.0.1)
57
+ slop (3.6.0)
58
+ thor (0.19.1)
59
+ thread_safe (0.3.5)
60
+ tzinfo (1.2.2)
61
+ thread_safe (~> 0.1)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ duration-formatter!
68
+ guard (~> 2.12)
69
+ guard-minitest (~> 2.4)
70
+ rb-fsevent (~> 0.9)
71
+
72
+ BUNDLED WITH
73
+ 1.10.3
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ clearing :on
2
+
3
+ guard :minitest do
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
5
+ watch(%r{^test/.+_test\.rb$})
6
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
7
+ end
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << 'lib'
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.verbose = false
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,24 @@
1
+ require './lib/duration_formatter/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'duration-formatter'
5
+ s.version = DurationFormatter::VERSION
6
+ s.authors = ["Richard Venneman"]
7
+ s.email = 'richardvenneman@me.com'
8
+ s.homepage =
9
+ 'https://github.com/richardvenneman/duration-formatter'
10
+ s.summary = 'Formatter for ruby-duration'
11
+ s.description = 'A simple gem to parse minutes into a readable format using
12
+ ruby-duration.'
13
+
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = Dir['test/**/*']
18
+
19
+ s.add_dependency 'ruby-duration', '~> 3.2'
20
+
21
+ s.add_development_dependency 'guard', '~> 2.12'
22
+ s.add_development_dependency 'guard-minitest', '~> 2.4'
23
+ s.add_development_dependency 'rb-fsevent', '~> 0.9'
24
+ end
@@ -0,0 +1,3 @@
1
+ module DurationFormatter
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'ruby-duration'
2
+
3
+ class FormattedDuration
4
+ DAYS_FORMAT = '%d %~d'
5
+ HOURS_FORMAT = '%h %~h'
6
+ MINUTES_FORMAT = '%m %~m'
7
+
8
+ def initialize(minutes)
9
+ @minutes = minutes % 60
10
+ @hours = minutes / 60
11
+ @days = @hours / 24
12
+ end
13
+
14
+ def format
15
+ dayless_hours = @hours % 24
16
+ output = []
17
+
18
+ output << Duration.new(days: @days).format(DAYS_FORMAT) if @days != 0
19
+ output << Duration.new(hours: dayless_hours).format(HOURS_FORMAT) if dayless_hours != 0
20
+ output << Duration.new(minutes: @minutes).format(MINUTES_FORMAT) if @minutes != 0
21
+
22
+ output.join(', ')
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class FormattedDurationTest < Minitest::Test
4
+ def test_days_only_duration
5
+ text = '1 day'
6
+ output = FormattedDuration.new(1440).format
7
+
8
+ assert_equal text, output
9
+ end
10
+
11
+ def test_hours_only_duration
12
+ text = '1 hour'
13
+ output = FormattedDuration.new(60).format
14
+
15
+ assert_equal text, output
16
+ end
17
+
18
+ def test_minutes_only_duration
19
+ text = '30 minutes'
20
+ output = FormattedDuration.new(30).format
21
+
22
+ assert_equal text, output
23
+ end
24
+
25
+ def test_days_and_hours_duration
26
+ text = '1 day, 4 hours'
27
+ output = FormattedDuration.new(1680).format
28
+
29
+ assert_equal text, output
30
+ end
31
+
32
+ def test_hours_and_minutes_duration
33
+ text = '1 hour, 30 minutes'
34
+ output = FormattedDuration.new(90).format
35
+
36
+ assert_equal text, output
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ require './lib/formatted_duration'
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duration-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Venneman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-duration
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rb-fsevent
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ description: |-
70
+ A simple gem to parse minutes into a readable format using
71
+ ruby-duration.
72
+ email: richardvenneman@me.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - Guardfile
80
+ - Rakefile
81
+ - duration-formatter.gemspec
82
+ - lib/duration_formatter/version.rb
83
+ - lib/formatted_duration.rb
84
+ - test/lib/formatted_duration_test.rb
85
+ - test/test_helper.rb
86
+ homepage: https://github.com/richardvenneman/duration-formatter
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.8
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Formatter for ruby-duration
110
+ test_files:
111
+ - test/lib/formatted_duration_test.rb
112
+ - test/test_helper.rb