time_duration_humanizer 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8ced2681ada1e708b76e747e98c9c0afb07a610
4
- data.tar.gz: 9b1c0ae8cb749c6e07ba8b52626d388b7ba46d88
3
+ metadata.gz: c9ea67a4041178b0a9d2e17f55f53b9ca04e8fa6
4
+ data.tar.gz: 5174c75e85618f1c997978db790f402efb0ce9df
5
5
  SHA512:
6
- metadata.gz: 94d3825574856ac207fdadfa2f45ee7f64ccee0791901892030204c5e6b4962dbc203db46f5cbf7f3096bd8ec5f6e2c297b5535d51b9506e863c827d8816995c
7
- data.tar.gz: b6c7e045bc4d7daffbe5df59e26180abf53a8a127d9bd5a681dbcad921a53f81da66e298fc6f4f0f9b595f15395acc14af63cef4ef1ce0ce8300b01319365526
6
+ metadata.gz: 65789569eeb769d3ffe6ee4a5155b338d083a5364d5535dba54eeaa5881b328157712feca25a9522d3b7adfdb230f4d053293d3c778fdd3c46569d129ef0f610
7
+ data.tar.gz: e29a7baa0d550aef8b3d2286396d5207c3d4aa140847ffee0643c5fcaa176ac334d4f72a9fd8782edfd4e4080427da1acb692ef760da83525ccdb5a8c8b930f8
data/Gemfile CHANGED
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in time_duration_humanizer.gemspec
4
4
  gemspec
5
5
 
6
- gem 'activesupport'
7
6
  gem 'i18n'
8
7
  gem 'minitest'
9
8
  gem 'rake'
data/README.md CHANGED
@@ -45,7 +45,7 @@ irb(main):006:0> TimeDurationHumanizer.humanize(62208000, { days_in_year: 360 })
45
45
  ## Options (second parameter)
46
46
 
47
47
  * and_at_end - default `true`
48
- * days_in_year - default `1.year / 1.day` (365.25)
48
+ * days_in_year - default `365.25`
49
49
 
50
50
  ## Units (third parameter)
51
51
 
@@ -1,3 +1,3 @@
1
1
  module TimeDurationHumanizer
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -1,13 +1,21 @@
1
1
  require "time_duration_humanizer/version"
2
2
 
3
3
  module TimeDurationHumanizer
4
- @@known_units = [:years, :months, :weeks, :days, :hours, :minutes, :seconds]
4
+ @@units = {
5
+ years: 31557600,
6
+ months: 2592000,
7
+ weeks: 604800,
8
+ days: 86400,
9
+ hours: 3600,
10
+ minutes: 60,
11
+ seconds: 1
12
+ }
5
13
 
6
14
  def self.humanize(seconds, options = {}, units = {})
7
15
  options = {
8
16
  and_at_end: true,
9
- days_in_year: 1.year / 1.day
10
- }.merge!(options.symbolize_keys)
17
+ days_in_year: 365.25
18
+ }.merge!(options)
11
19
 
12
20
  units = {
13
21
  years: true,
@@ -17,14 +25,14 @@ module TimeDurationHumanizer
17
25
  hours: true,
18
26
  minutes: true,
19
27
  seconds: true
20
- }.merge!(units.symbolize_keys)
28
+ }.merge!(units)
21
29
 
22
30
  values = []
23
31
  duration = ''
24
32
 
25
33
  units.each do |k, v|
26
- if v == true && @@known_units.include?(k)
27
- u = (k == :years ? options[:days_in_year].days : 1.send(k)).to_i
34
+ if v == true && @@units.keys.include?(k)
35
+ u = k == :years ? (options[:days_in_year] * @@units[:days]).to_i : @@units[k]
28
36
  value = seconds >= u ? seconds / u : 0
29
37
  if value > 0
30
38
  values << { name: k.to_s, value: value }
@@ -36,7 +44,7 @@ module TimeDurationHumanizer
36
44
  l = values.length
37
45
  values.each_with_index do |v, i|
38
46
  separator = i == l - 1 ? '' : (i == l - 2 && options[:and_at_end] == true ? " #{I18n.t('time_duration_humanizer.and')} " : ', ')
39
- duration += "#{v[:value]} #{I18n.t("time_duration_humanizer.#{v[:value] == 1 ? v[:name].singularize : v[:name]}")}#{separator}"
47
+ duration += "#{v[:value]} #{I18n.t("time_duration_humanizer.#{v[:value] == 1 ? v[:name].chop : v[:name]}")}#{separator}"
40
48
  end
41
49
 
42
50
  duration
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Nikolay Digaev"]
10
10
  spec.email = ["ffs.cmp@gmail.com"]
11
11
 
12
- spec.summary = %q{An Ruby gem for converting seconds into human-readable format.}
13
- spec.description = %q{An Ruby gem for converting seconds into human-readable format (12345 => "3 hours, 25 minutes and 45 seconds").}
12
+ spec.summary = %q{A Ruby gem for converting seconds into human-readable format.}
13
+ spec.description = %q{A Ruby gem for converting seconds into human-readable format (12345 => "3 hours, 25 minutes and 45 seconds").}
14
14
  spec.homepage = "https://github.com/digaev/time_duration_humanier"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_duration_humanizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikolay Digaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-11 00:00:00.000000000 Z
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: An Ruby gem for converting seconds into human-readable format (12345
42
- => "3 hours, 25 minutes and 45 seconds").
41
+ description: A Ruby gem for converting seconds into human-readable format (12345 =>
42
+ "3 hours, 25 minutes and 45 seconds").
43
43
  email:
44
44
  - ffs.cmp@gmail.com
45
45
  executables: []
@@ -80,5 +80,5 @@ rubyforge_project:
80
80
  rubygems_version: 2.4.5.1
81
81
  signing_key:
82
82
  specification_version: 4
83
- summary: An Ruby gem for converting seconds into human-readable format.
83
+ summary: A Ruby gem for converting seconds into human-readable format.
84
84
  test_files: []