natural_time 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2d57766e0968c55b0bc7d844b30034f46bae8255
4
- data.tar.gz: d78085265e9ddaee19ceec9dea81950a6a4e22dd
2
+ SHA256:
3
+ metadata.gz: f93b0e487a332d71b0a5751d366950478e56275476f405a3747e8fdcfbbb7deb
4
+ data.tar.gz: 2031102f88c016a6503c41dcc8f5908f18fbe016952df23c7dfa5102150a17b4
5
5
  SHA512:
6
- metadata.gz: 945dd465bac00fd0025fea1dc0d4099285172616153ea094086ed216cc04b19057f7ac9421140aa8ef2ff86a2cac4d30e50404afd902c094ecbba47bdc9bc5ab
7
- data.tar.gz: ee8caa70551a844dafa434fb5b15d5395a1538ad8750957a204b934573fb2f833529b78f014e8314c5b892cfb41f15d4302861782c5508233b93c39b59628eff
6
+ metadata.gz: 79a73e4faab5d6931451851d26d3e82385807c6a0b10632bea5f6f85a6fc3113c5238c3c468575efde37319e9ec22370dda4bdcf015aa980a63bba13b78171b9
7
+ data.tar.gz: 202a0fd2e3bd54ba7cb2ab6bb51b2fa2025e816bd75ba9e6cafb174620c494b34fd9c56b4fbc60120ae282f1487e078fd1a21d9a599851d9ffa5baba56ec1c20
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
2
4
 
3
5
  # Specify your gem's dependencies in natural_time.gemspec
4
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,20 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- natural_time (0.0.5)
5
- activesupport
4
+ natural_time (0.3.0)
5
+ activesupport (~> 5.1.4)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (3.2.6)
11
- i18n (~> 0.6)
12
- multi_json (~> 1.0)
13
- i18n (0.6.0)
14
- multi_json (1.3.6)
10
+ activesupport (5.1.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ coderay (1.1.2)
16
+ concurrent-ruby (1.0.5)
17
+ diff-lcs (1.3)
18
+ i18n (0.9.1)
19
+ concurrent-ruby (~> 1.0)
20
+ method_source (0.9.0)
21
+ minitest (5.11.0)
22
+ pry (0.11.3)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.9.0)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.0)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.0)
39
+ thread_safe (0.3.6)
40
+ tzinfo (1.2.4)
41
+ thread_safe (~> 0.1)
15
42
 
16
43
  PLATFORMS
17
44
  ruby
18
45
 
19
46
  DEPENDENCIES
47
+ bundler (~> 1.16)
20
48
  natural_time!
49
+ pry (~> 0.11)
50
+ rake (~> 10.0)
51
+ rspec (~> 3.0)
52
+
53
+ BUNDLED WITH
54
+ 1.16.1
@@ -1,47 +1,47 @@
1
- = natural_time
1
+ # NaturalTime
2
2
 
3
3
  NaturalTime outputs a duration in natural language.
4
4
 
5
- == Usage
5
+ ## Usage
6
6
 
7
- === Sentence
7
+ ### Sentence
8
8
 
9
9
  The <tt>to_sentence</tt> method will output the duration in time in natural language
10
10
  and formatted like a sentence.
11
11
 
12
- NaturalTime.new(65).to_sentence #=> "1 minute and 5 seconds"
12
+ NaturalTime.new(65).to_sentence #> "1 minute and 5 seconds"
13
13
 
14
- NaturalTime.new(120).to_sentence #=> "2 minutes"
14
+ NaturalTime.new(120).to_sentence #> "2 minutes"
15
15
 
16
- NaturalTime.new(10000).to_sentence #=> "2 hours, 46 minutes, and 40 seconds"
16
+ NaturalTime.new(10000).to_sentence #> "2 hours, 46 minutes, and 40 seconds"
17
17
 
18
- === String
18
+ ### String
19
19
 
20
20
  The <tt>to_s</tt> command will separate the units with commas but with no "and":
21
21
 
22
- NaturalTime.new(65).to_s #=> "1 minute, 5 seconds"
22
+ NaturalTime.new(65).to_s #> "1 minute, 5 seconds"
23
23
 
24
- NaturalTime.new(10000).to_s #=> "2 hours, 46 minutes, 40 seconds"
25
-
26
- === Array
24
+ NaturalTime.new(10000).to_s #> "2 hours, 46 minutes, 40 seconds"
25
+
26
+ ### Array
27
27
 
28
28
  NaturalTime instances can also be output to an array with <tt>to_a</tt>:
29
29
 
30
- NaturalTime.new(65).to_a #=> ["1 minutes", "5 seconds"]
31
-
32
- NaturalTime.new(120).to_a #=> ["2 minutes"]
30
+ NaturalTime.new(65).to_a #> ["1 minutes", "5 seconds"]
31
+
32
+ NaturalTime.new(120).to_a #> ["2 minutes"]
33
33
 
34
- === Precision
34
+ ### Precision
35
35
 
36
36
  NaturalTime can return the amount of time to a specific precision. If all you want is the greatest unit:
37
37
 
38
- NaturalTime.new(65, :precision => 1).to_sentence #=> "1 minute"
39
-
40
- NaturalTime.new(10000, :precision => 1).to_sentence #=> "2 hours"
41
-
42
- NaturalTime.new(10000, :precision => 2).to_sentence #=> "2 hours and 46 minutes"
38
+ NaturalTime.new(65, :precision#> 1).to_sentence #=> "1 minute"
39
+
40
+ NaturalTime.new(10000, :precision#> 1).to_sentence #=> "2 hours"
43
41
 
44
- === Distance
42
+ NaturalTime.new(10000, :precision#> 2).to_sentence #=> "2 hours and 46 minutes"
43
+
44
+ ### Distance
45
45
 
46
46
  If you want to use NaturalTime to show an elapsed time and you don't care if it's in the
47
47
  past or the future, use the <tt>natural_time</tt> or <tt>to_sentence</tt> methods, or the
@@ -50,19 +50,19 @@ past or the future, use the <tt>natural_time</tt> or <tt>to_sentence</tt> method
50
50
  If you're measuring distances that may be in the past or the future, the <tt>distance</tt>
51
51
  method will return a sentence indicating how long ago or in the future is your duration.
52
52
 
53
- NaturalTime.new(65).distance #=> "1 minute and 5 seconds from now"
54
-
55
- NaturalTime.new(-65).distance #=> "1 minute and 5 seconds ago"
56
-
53
+ NaturalTime.new(65).distance #> "1 minute and 5 seconds from now"
54
+
55
+ NaturalTime.new(-65).distance #> "1 minute and 5 seconds ago"
56
+
57
57
  It works with <tt>:precision</tt> too:
58
-
59
- NaturalTime.new(10000, :precision => 1).distance #=> "2 hours from now"
60
-
61
- NaturalTime.new(-10000, :precision => 2).distance #=> "2 hours and 46 minutes ago"
62
58
 
59
+ NaturalTime.new(10000, :precision#> 1).distance #=> "2 hours from now"
60
+
61
+ NaturalTime.new(-10000, :precision#> 2).distance#=> "2 hours and 46 minutes ago"
62
+
63
+
64
+ ## Note on Patches/Pull Requests
63
65
 
64
- == Note on Patches/Pull Requests
65
-
66
66
  * Fork the project.
67
67
  * Make your feature addition or bug fix.
68
68
  * Add tests for it. This is important so I don't break it in a
@@ -71,6 +71,6 @@ It works with <tt>:precision</tt> too:
71
71
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
72
72
  * Send me a pull request. Bonus points for topic branches.
73
73
 
74
- == Copyright
74
+ ## Copyright
75
75
 
76
- Copyright (c) 2010 Jeff Coleman. See LICENSE for details.
76
+ Copyright (c) 2018 Isaac Priestley. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "natural_time"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/natural_time.rb CHANGED
@@ -1,12 +1,11 @@
1
- require 'rubygems'
2
- require 'active_support/core_ext/integer'
3
- require 'active_support/core_ext/numeric'
1
+ require "natural_time/version"
2
+ require 'active_support/core_ext/integer/time'
4
3
 
5
4
  class NaturalTime
6
5
  attr_accessor :duration, :precision, :past
7
6
 
8
7
  UNITS_OF_TIME = [["year", "years"], ["month", "months"], ["week", "weeks"], ["day", "days"], ["hour", "hours"], ["minute", "minutes"]]
9
-
8
+
10
9
  def initialize(duration_in_seconds, options={})
11
10
  @precision = options[:precision]
12
11
  duration_in_seconds = duration_in_seconds.to_i
@@ -14,27 +13,27 @@ class NaturalTime
14
13
  @duration = duration_in_seconds.abs
15
14
  elapsed_time = elapsed_time(duration_in_seconds)
16
15
  end
17
-
16
+
18
17
  def to_sentence
19
18
  to_array.to_sentence
20
19
  end
21
-
20
+
22
21
  def natural_time
23
22
  to_array.join(", ")
24
23
  end
25
-
24
+
26
25
  def to_s
27
26
  natural_time
28
27
  end
29
-
28
+
30
29
  def to_a
31
30
  [elapsed_time(duration)].flatten
32
31
  end
33
-
32
+
34
33
  def to_array
35
34
  to_a
36
35
  end
37
-
36
+
38
37
  def distance
39
38
  if past
40
39
  modifier = "ago"
@@ -43,25 +42,25 @@ class NaturalTime
43
42
  end
44
43
  "#{to_sentence} #{modifier}"
45
44
  end
46
-
45
+
47
46
  def elapsed_time(duration_in_seconds)
48
47
  return "0 seconds" if duration_in_seconds <= 0
49
48
 
50
49
  elapsed_time = []
51
50
 
52
51
  seconds_left = duration_in_seconds
53
-
52
+
54
53
  UNITS_OF_TIME.each do |period|
55
54
  amount = (seconds_left / 1.send(period.first)).to_i
56
55
  str = amount == 1 ? period[0] : period[1]
57
56
  elapsed_time << "#{amount} #{str}" if amount > 0
58
57
  seconds_left = seconds_left % 1.send(period.first)
59
58
  end
60
-
59
+
61
60
  seconds = seconds_left % 1.minute
62
61
  str = seconds == 1 ? "second" : "seconds"
63
- elapsed_time << "#{seconds.to_i} #{str}" unless (seconds == 0 && elapsed_time.compact.length > 0)
64
-
62
+ elapsed_time << "#{seconds.to_i} #{str}" unless (seconds == 0 && elapsed_time.compact.length > 0)
63
+
65
64
  if precision
66
65
  elapsed_time.compact.first(precision)
67
66
  else
@@ -0,0 +1,3 @@
1
+ class NaturalTime
2
+ VERSION = "0.3.0"
3
+ end
data/natural_time.gemspec CHANGED
@@ -1,52 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
1
 
6
- Gem::Specification.new do |s|
7
- s.name = "natural_time"
8
- s.version = "0.2.1"
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "natural_time/version"
9
5
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Isaac Priestley"]
12
- s.date = "2013-08-26"
13
- s.description = "Smart enumeration of durations in natural language--\"4 hours, 3 minutes and 2 seconds\""
14
- s.email = "progressions@gmail.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".ruby-version",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "History.txt",
25
- "LICENSE",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "lib/natural_time.rb",
30
- "natural_time.gemspec",
31
- "spec/natural_time_spec.rb",
32
- "spec/spec.opts",
33
- "spec/spec_helper.rb"
34
- ]
35
- s.homepage = "http://github.com/progressions/natural_time"
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.12"
38
- s.summary = "Smart enumeration of durations in natural language"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "natural_time"
8
+ spec.version = NaturalTime::VERSION
9
+ spec.authors = ["Isaac Priestley"]
10
+ spec.email = ["progressions@gmail.com"]
39
11
 
40
- if s.respond_to? :specification_version then
41
- s.specification_version = 3
12
+ spec.summary = "Smart enumeration of durations in natural language"
13
+ spec.description = "Smart enumeration of durations in natural language--\"4 hours, 3 minutes and 2 seconds\""
14
+ spec.homepage = "https://github.com/progressions/natural_time"
42
15
 
43
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
45
- else
46
- s.add_dependency(%q<activesupport>, [">= 0"])
47
- end
48
- else
49
- s.add_dependency(%q<activesupport>, [">= 0"])
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
50
18
  end
51
- end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
52
22
 
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "pry", "~> 0.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_dependency "activesupport", "~> 5.1.4"
28
+ end
metadata CHANGED
@@ -1,53 +1,106 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natural_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Priestley
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2013-08-26 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: activesupport
15
71
  requirement: !ruby/object:Gem::Requirement
16
72
  requirements:
17
- - - '>='
73
+ - - "~>"
18
74
  - !ruby/object:Gem::Version
19
- version: '0'
75
+ version: 5.1.4
20
76
  type: :runtime
21
77
  prerelease: false
22
78
  version_requirements: !ruby/object:Gem::Requirement
23
79
  requirements:
24
- - - '>='
80
+ - - "~>"
25
81
  - !ruby/object:Gem::Version
26
- version: '0'
82
+ version: 5.1.4
27
83
  description: Smart enumeration of durations in natural language--"4 hours, 3 minutes
28
84
  and 2 seconds"
29
- email: progressions@gmail.com
85
+ email:
86
+ - progressions@gmail.com
30
87
  executables: []
31
88
  extensions: []
32
- extra_rdoc_files:
33
- - LICENSE
34
- - README.rdoc
89
+ extra_rdoc_files: []
35
90
  files:
36
- - .document
37
- - .ruby-version
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
38
94
  - Gemfile
39
95
  - Gemfile.lock
40
- - History.txt
41
- - LICENSE
42
- - README.rdoc
96
+ - README.md
43
97
  - Rakefile
44
- - VERSION
98
+ - bin/console
99
+ - bin/setup
45
100
  - lib/natural_time.rb
101
+ - lib/natural_time/version.rb
46
102
  - natural_time.gemspec
47
- - spec/natural_time_spec.rb
48
- - spec/spec.opts
49
- - spec/spec_helper.rb
50
- homepage: http://github.com/progressions/natural_time
103
+ homepage: https://github.com/progressions/natural_time
51
104
  licenses: []
52
105
  metadata: {}
53
106
  post_install_message:
@@ -56,18 +109,18 @@ require_paths:
56
109
  - lib
57
110
  required_ruby_version: !ruby/object:Gem::Requirement
58
111
  requirements:
59
- - - '>='
112
+ - - ">="
60
113
  - !ruby/object:Gem::Version
61
114
  version: '0'
62
115
  required_rubygems_version: !ruby/object:Gem::Requirement
63
116
  requirements:
64
- - - '>='
117
+ - - ">="
65
118
  - !ruby/object:Gem::Version
66
119
  version: '0'
67
120
  requirements: []
68
121
  rubyforge_project:
69
- rubygems_version: 2.0.6
122
+ rubygems_version: 2.7.3
70
123
  signing_key:
71
- specification_version: 3
124
+ specification_version: 4
72
125
  summary: Smart enumeration of durations in natural language
73
126
  test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.0.0-p247@natural_time
data/History.txt DELETED
@@ -1,10 +0,0 @@
1
- == 0.0.3 2010-01-22
2
- * major enhancements
3
- * specify level of precision
4
- * distance method shows whether it's past or future
5
- * minor enhancements
6
- * bug fixes
7
-
8
- == 0.0.2 2010-01-13
9
- * major enhancements
10
- * outputs duration of time in natural language
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Jeff Coleman
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,305 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Naturaltime" do
4
- describe "seconds" do
5
- it "should return zero seconds" do
6
- NaturalTime.new(0).natural_time.should == "0 seconds"
7
- end
8
-
9
- it "should return singular" do
10
- NaturalTime.new(1).natural_time.should == "1 second"
11
- end
12
-
13
- it "should return seconds" do
14
- (2..59).each do |i|
15
- NaturalTime.new(i).natural_time.should == "#{i} seconds"
16
- end
17
- end
18
-
19
- it "should not return 60 seconds" do
20
- NaturalTime.new(60.seconds).natural_time.should_not match(/60 seconds/)
21
- end
22
-
23
- it "should return remainder in seconds" do
24
- NaturalTime.new(65.seconds).natural_time.should match(/ 5 seconds/)
25
- end
26
- end
27
-
28
- describe "minutes" do
29
- it "should return singular" do
30
- NaturalTime.new(60.seconds).natural_time.should == "1 minute"
31
- end
32
-
33
- it "should return whole minutes" do
34
- (2..59).each do |i|
35
- NaturalTime.new(i.minutes).natural_time.should == "#{i} minutes"
36
- end
37
- end
38
-
39
- it "should not return 60 minutes" do
40
- NaturalTime.new(60.minutes).natural_time.should_not match(/60 minutes/)
41
- end
42
-
43
- it "should return remainder in seconds" do
44
- NaturalTime.new(65.seconds).natural_time.should == "1 minute, 5 seconds"
45
- end
46
- end
47
-
48
- describe "hours" do
49
- it "should return singular" do
50
- NaturalTime.new(1.hour).natural_time.should == "1 hour"
51
- end
52
-
53
- it "should return whole hours" do
54
- (2..23).each do |i|
55
- NaturalTime.new(i.hours).natural_time.should == "#{i} hours"
56
- end
57
- end
58
-
59
- it "should not return 24 hours" do
60
- NaturalTime.new(24.hours).natural_time.should_not match(/24 hours/)
61
- end
62
-
63
- it "should return remainder in minutes" do
64
- NaturalTime.new(1.hour + 5.minutes).natural_time.should == "1 hour, 5 minutes"
65
- end
66
-
67
- it "should return remainder in minutes and seconds" do
68
- NaturalTime.new(1.hour + 5.minutes + 5.seconds).natural_time.should == "1 hour, 5 minutes, 5 seconds"
69
- end
70
- end
71
-
72
- describe "days" do
73
- it "should return singular" do
74
- NaturalTime.new(1.day).natural_time.should == "1 day"
75
- end
76
-
77
- it "should return whole days" do
78
- (2..6).each do |i|
79
- NaturalTime.new(i.days).natural_time.should == "#{i} days"
80
- end
81
- end
82
-
83
- it "should not return 7 days" do
84
- NaturalTime.new(7.days).natural_time.should_not match(/7 days/)
85
- end
86
-
87
- it "should return remainder in hours" do
88
- NaturalTime.new(1.day + 1.hour).natural_time.should == "1 day, 1 hour"
89
- end
90
-
91
- it "should return remainder in hours and minutes" do
92
- NaturalTime.new(1.day + 1.hour + 5.minutes).natural_time.should == "1 day, 1 hour, 5 minutes"
93
- end
94
-
95
- it "should return remainder in hours and minutes and seconds" do
96
- NaturalTime.new(1.day + 1.hour + 5.minutes + 5.seconds).natural_time.should == "1 day, 1 hour, 5 minutes, 5 seconds"
97
- end
98
- end
99
-
100
- describe "weeks" do
101
- it "should return singular" do
102
- NaturalTime.new(1.week).natural_time.should == "1 week"
103
- end
104
-
105
- it "should return whole weeks" do
106
- (2..4).each do |i|
107
- NaturalTime.new(i.weeks).natural_time.should == "#{i} weeks"
108
- end
109
- end
110
-
111
- it "should not return 5 weeks" do
112
- NaturalTime.new(5.weeks).natural_time.should_not match(/5 weeks/)
113
- end
114
-
115
- it "should return remainder in days" do
116
- NaturalTime.new(1.week + 1.day).natural_time.should == "1 week, 1 day"
117
- end
118
-
119
- it "should return remainder in days and hours" do
120
- NaturalTime.new(1.week + 1.day + 1.hour).natural_time.should == "1 week, 1 day, 1 hour"
121
- end
122
-
123
- it "should return remainder in days and hours and minutes" do
124
- NaturalTime.new(1.week + 1.day + 1.hour + 5.minutes).natural_time.should == "1 week, 1 day, 1 hour, 5 minutes"
125
- end
126
-
127
- it "should return remainder in days and hours and minutes and seconds" do
128
- NaturalTime.new(1.week + 1.day + 1.hour + 5.minutes + 5.seconds).natural_time.should == "1 week, 1 day, 1 hour, 5 minutes, 5 seconds"
129
- end
130
- end
131
-
132
- describe "months" do
133
- it "should return singular" do
134
- NaturalTime.new(1.month).natural_time.should == "1 month"
135
- end
136
-
137
- it "should return whole months" do
138
- (2..4).each do |i|
139
- NaturalTime.new(i.months).natural_time.should == "#{i} months"
140
- end
141
- end
142
-
143
- it "should not return 12 months" do
144
- NaturalTime.new(13.months).natural_time.should_not match(/13 months/)
145
- end
146
-
147
- it "should return remainder in weeks" do
148
- NaturalTime.new(1.month + 1.week).natural_time.should == "1 month, 1 week"
149
- end
150
-
151
- it "should return remainder in days" do
152
- NaturalTime.new(1.month + 1.week + 1.day).natural_time.should == "1 month, 1 week, 1 day"
153
- end
154
-
155
- it "should return remainder in days and hours" do
156
- NaturalTime.new(1.month + 1.week + 1.day + 1.hour).natural_time.should == "1 month, 1 week, 1 day, 1 hour"
157
- end
158
-
159
- it "should return remainder in days and hours and minutes" do
160
- NaturalTime.new(1.month + 1.week + 1.day + 1.hour + 5.minutes).natural_time.should == "1 month, 1 week, 1 day, 1 hour, 5 minutes"
161
- end
162
-
163
- it "should return remainder in days and hours and minutes and seconds" do
164
- NaturalTime.new(1.month + 1.week + 1.day + 1.hour + 5.minutes + 5.seconds).natural_time.should == "1 month, 1 week, 1 day, 1 hour, 5 minutes, 5 seconds"
165
- end
166
- end
167
-
168
- describe "years" do
169
- it "should return singular" do
170
- NaturalTime.new(1.year).natural_time.should == "1 year"
171
- end
172
-
173
- it "should return whole years" do
174
- (2..4).each do |i|
175
- NaturalTime.new(i.years).natural_time.should == "#{i} years"
176
- end
177
- end
178
-
179
- it "should return remainder in months" do
180
- NaturalTime.new(1.year + 1.month).natural_time.should == "1 year, 1 month"
181
- end
182
-
183
- it "should return remainder in months and weeks" do
184
- NaturalTime.new(1.year + 1.month + 1.week).natural_time.should == "1 year, 1 month, 1 week"
185
- end
186
-
187
- it "should return remainder in months and days" do
188
- NaturalTime.new(1.year + 1.month + 1.week + 1.day).natural_time.should == "1 year, 1 month, 1 week, 1 day"
189
- end
190
-
191
- it "should return remainder in months and days and hours" do
192
- NaturalTime.new(1.year + 1.month + 1.week + 1.day + 1.hour).natural_time.should == "1 year, 1 month, 1 week, 1 day, 1 hour"
193
- end
194
-
195
- it "should return remainder in months and days and hours and minutes" do
196
- NaturalTime.new(1.year + 1.month + 1.week + 1.day + 1.hour + 5.minutes).natural_time.should == "1 year, 1 month, 1 week, 1 day, 1 hour, 5 minutes"
197
- end
198
-
199
- it "should return remainder in months and days and hours and minutes and seconds" do
200
- NaturalTime.new(1.year + 1.month + 1.week + 1.day + 1.hour + 5.minutes + 5.seconds).natural_time.should == "1 year, 1 month, 1 week, 1 day, 1 hour, 5 minutes, 5 seconds"
201
- end
202
-
203
- describe "precision" do
204
- it "should limit the precision to 1" do
205
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 1).natural_time.should == "1 week"
206
- end
207
-
208
- it "should limit the precision to 2" do
209
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 2).natural_time.should == "1 week, 1 minute"
210
- end
211
-
212
- it "should show the distance with precision of 1 in the past" do
213
- distance = -1 * (1.week + 1.minutes + 1.second)
214
- NaturalTime.new(distance, :precision => 1).distance.should == "1 week ago"
215
- end
216
-
217
- it "should show the distance with precision of 2 in the past" do
218
- distance = -1 * (1.week + 1.minutes + 1.second)
219
- NaturalTime.new(distance, :precision => 2).distance.should == "1 week and 1 minute ago"
220
- end
221
-
222
- it "should show the distance with precision of 1 in the future" do
223
- distance = (1.week + 1.minutes + 1.second)
224
- NaturalTime.new(distance, :precision => 1).distance.should == "1 week from now"
225
- end
226
-
227
- it "should show the distance with precision of 2 in the future" do
228
- distance = (1.week + 1.minutes + 1.second)
229
- NaturalTime.new(distance, :precision => 2).distance.should == "1 week and 1 minute from now"
230
- end
231
- end
232
-
233
- describe "distances" do
234
- it "should give the distance in the past" do
235
- NaturalTime.new(-1).distance.should == "1 second ago"
236
- end
237
-
238
- it "should give the distance in the past" do
239
- NaturalTime.new(-2).distance.should == "2 seconds ago"
240
- end
241
- it "should give the distance in the future" do
242
- NaturalTime.new(1).distance.should == "1 second from now"
243
- end
244
-
245
- it "should give the distance in the future" do
246
- NaturalTime.new(2).distance.should == "2 seconds from now"
247
- end
248
- end
249
- end
250
-
251
- describe "to_s" do
252
- it "should equal natural_time" do
253
- (1..100).each do |i|
254
- @natural_time = NaturalTime.new(i)
255
- @natural_time.to_s.should == @natural_time.natural_time
256
- end
257
- end
258
-
259
- describe "precision" do
260
- it "should limit the precision to 1" do
261
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 1).to_s.should == "1 week"
262
- end
263
-
264
- it "should limit the precision to 2" do
265
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 2).to_s.should == "1 week, 1 minute"
266
- end
267
- end
268
- end
269
-
270
- describe "to_sentence" do
271
- it "should put 'and' before the last entry in the list" do
272
- NaturalTime.new(1.minute + 1.second).to_sentence.should == "1 minute and 1 second"
273
- end
274
-
275
- describe "precision" do
276
- it "should limit the precision to 1" do
277
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 1).to_sentence.should == "1 week"
278
- end
279
-
280
- it "should limit the precision to 2" do
281
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 2).to_sentence.should == "1 week and 1 minute"
282
- end
283
- end
284
- end
285
-
286
- describe "to_array" do
287
- it "should return an array" do
288
- NaturalTime.new(1.minutes + 1.second).to_array.should == ["1 minute", "1 second"]
289
- end
290
-
291
- it "should return an array" do
292
- NaturalTime.new(1.minutes + 1.second).to_a.should == ["1 minute", "1 second"]
293
- end
294
-
295
- describe "precision" do
296
- it "should limit the precision to 1" do
297
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 1).to_a.should == ["1 week"]
298
- end
299
-
300
- it "should limit the precision to 2" do
301
- NaturalTime.new(1.week + 1.minutes + 1.second, :precision => 2).to_a.should == ["1 week", "1 minute"]
302
- end
303
- end
304
- end
305
- end
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'natural_time'
4
- require 'rspec'
5
-
6
- RSpec.configure do |config|
7
-
8
- end