time_duration 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/time_duration.rb +12 -0
- data/lib/time_duration/duration.rb +48 -0
- data/lib/time_duration/locales/de.yml +7 -0
- data/lib/time_duration/locales/en.yml +7 -0
- data/lib/time_duration/locales/fr.yml +7 -0
- data/lib/time_duration/locales/pt-BR.yml +7 -0
- data/lib/time_duration/locales/ru.yml +9 -0
- data/lib/time_duration/version.rb +3 -0
- data/time_duration.gemspec +25 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 968b1e821f31fcc4cfa689d4f2455c6f10bdba0b
|
4
|
+
data.tar.gz: cb19dcba54ef14d9f3a4af993e69d75f62ebc4d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2700b198cbb1defe3d85790c56eba517ca36b9e65eaa3dc68f260facc708551845ab1e7b70aa709d4a25ddd5886b0fc0d9ce54f4ed9722a953a693ab893a8ec
|
7
|
+
data.tar.gz: 834023e1a4a561df245485fdf881ee72ad7a3c464c3413953c5d0543b4a9970299b60320432ed2acc6103031ff8002a02fc0dec54b8bdbf6d253a55cdfbb1e4f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# TimeDuration
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/time_duration`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'time_duration'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install time_duration
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/time_duration.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "time_duration"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "i18n"
|
2
|
+
require "time_duration/version"
|
3
|
+
require "time_duration/duration"
|
4
|
+
|
5
|
+
files = Dir[File.join(File.dirname(__FILE__), "time_duration/locales/*.yml")]
|
6
|
+
I18n.load_path.concat(files)
|
7
|
+
|
8
|
+
module TimeDuration
|
9
|
+
def self.t(duration, locale = :en)
|
10
|
+
Duration.new(duration, locale).to_s
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module TimeDuration
|
2
|
+
class Duration
|
3
|
+
def initialize(duration, locale = :en)
|
4
|
+
@duration = duration
|
5
|
+
@locale = locale
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
if hours == 0
|
10
|
+
format_minutes(false)
|
11
|
+
else
|
12
|
+
format_hours_and_minutes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def format_hours_and_minutes
|
19
|
+
if minutes == 0
|
20
|
+
format_hours
|
21
|
+
else
|
22
|
+
format_hours + format_minutes
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def format_hours
|
27
|
+
I18n.t("x_hours", count: hours, locale: @locale)
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_minutes(leading_zero = true)
|
31
|
+
formated_minutes = minutes
|
32
|
+
|
33
|
+
if leading_zero
|
34
|
+
formated_minutes = minutes.to_s.rjust(2, '0')
|
35
|
+
end
|
36
|
+
|
37
|
+
I18n.t("x_minutes", count: formated_minutes, locale: @locale)
|
38
|
+
end
|
39
|
+
|
40
|
+
def hours
|
41
|
+
@hours ||= @duration / 60
|
42
|
+
end
|
43
|
+
|
44
|
+
def minutes
|
45
|
+
@minutes ||= @duration % 60
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'time_duration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "time_duration"
|
8
|
+
spec.version = TimeDuration::VERSION
|
9
|
+
spec.authors = ["Joffrey JAFFEUX"]
|
10
|
+
spec.email = ["j.jaffeux@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Localized durations}
|
13
|
+
spec.description = %q{Localized durations}
|
14
|
+
spec.homepage = "https://github.com/hurikat/time_duration"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
24
|
+
spec.add_dependency "i18n", "~> 0.7.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: time_duration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joffrey JAFFEUX
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.0
|
69
|
+
description: Localized durations
|
70
|
+
email:
|
71
|
+
- j.jaffeux@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/time_duration.rb
|
84
|
+
- lib/time_duration/duration.rb
|
85
|
+
- lib/time_duration/locales/de.yml
|
86
|
+
- lib/time_duration/locales/en.yml
|
87
|
+
- lib/time_duration/locales/fr.yml
|
88
|
+
- lib/time_duration/locales/pt-BR.yml
|
89
|
+
- lib/time_duration/locales/ru.yml
|
90
|
+
- lib/time_duration/version.rb
|
91
|
+
- time_duration.gemspec
|
92
|
+
homepage: https://github.com/hurikat/time_duration
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Localized durations
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|