timeago 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ class TimeAgo
4
4
 
5
5
  def self.right_now
6
6
  time = Time.new
7
- time.strftime("%I:%M:%S %p")
7
+ time.strftime("%I:%M:%S %p")
8
8
  end
9
9
 
10
10
  def self.readable(time)
@@ -13,63 +13,62 @@ class TimeAgo
13
13
  backthen = time
14
14
 
15
15
  delta_setting = (rightnow.to_i - backthen.to_i).floor / 60
16
-
17
- distance = distance_of_time_in_words(delta_setting)
18
- return "#{distance} ago"
19
-
20
- if rightnow.to_i == backthen.to_i
21
- "just now"
16
+
17
+ distance = distance_of_time_in_words(delta_setting)
18
+ return "#{distance} ago"
19
+ if rightnow.to_i == backthen.to_i
20
+ "just now"
22
21
  elsif delta_minutes.abs <= (8724*60)
23
- distance = distance_of_time_in_words(delta_minutes)
24
- if distance <= (8724*60)
25
- return "#{distance} from now"
26
- else
27
- return "#{distance} ago"
28
- end
22
+ distance = distance_of_time_in_words(delta_minutes)
23
+ if distance <= (8724*60)
24
+ return "#{distance} from now"
25
+ else
26
+ return "#{distance} ago"
27
+ end
29
28
  else
30
- return "on #{DateTime.now.to_formatted_s(date_format)}"
31
- end
29
+ return "on #{DateTime.now.to_formatted_s(date_format)}"
30
+ end
32
31
  end
33
32
 
34
- def self.distance_of_time_in_words(minutes)
35
- case
36
- when minutes < 0.4
37
- "a few seconds"
38
- when minutes < 0.6
39
- "half a minute"
40
- when minutes < 1
41
- "less than a minute"
42
- when minutes < 2
43
- "one minute"
44
- when minutes < 45
45
- "#{minutes} minutes"
46
- when minutes < 59
47
- "less than one hour"
48
- when minutes < 120
49
- "one hour"
50
- when minutes < 1080
51
- "#{(minutes / 60).round} hours"
52
- when minutes < 1440
53
- "one day"
54
- when minutes < 2880
55
- "about one day"
56
- when minutes < 8640
57
- "#{(minutes / 1440).round} days"
58
- when minutes < 10080
59
- "one week"
60
- when minutes < 40320
61
- "#{(minutes / 8640).round} weeks"
62
- when minutes < 43200
63
- "one month"
64
- when minutes < 525580
65
- "#{(minutes / 43200).round} months"
66
- when minutes < 525600
67
- "one year"
68
- when minutes < 2628000
69
- "#{(minutes / 525600).round} years"
70
- else
71
- "#{minutes} minutes"
72
- end
73
- end
33
+ def self.distance_of_time_in_words(minutes)
34
+ case
35
+ when minutes < 0.4
36
+ "a few seconds"
37
+ when minutes < 0.6
38
+ "half a minute"
39
+ when minutes < 1
40
+ "less than a minute"
41
+ when minutes < 2
42
+ "one minute"
43
+ when minutes < 45
44
+ "#{minutes} minutes"
45
+ when minutes < 59
46
+ "less than one hour"
47
+ when minutes < 120
48
+ "one hour"
49
+ when minutes < 1080
50
+ "#{(minutes / 60).round} hours"
51
+ when minutes < 1440
52
+ "one day"
53
+ when minutes < 2880
54
+ "about one day"
55
+ when minutes < 8640
56
+ "#{(minutes / 1440).round} days"
57
+ when minutes < 10080
58
+ "one week"
59
+ when minutes < 40320
60
+ "#{(minutes / 8640).round} weeks"
61
+ when minutes < 43200
62
+ "one month"
63
+ when minutes < 525580
64
+ "#{(minutes / 43200).round} months"
65
+ when minutes < 525600
66
+ "one year"
67
+ when minutes < 2628000
68
+ "#{(minutes / 525600).round} years"
69
+ else
70
+ "#{minutes} minutes"
71
+ end
72
+ end
74
73
 
75
74
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeago
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Frederik Reich
@@ -15,105 +15,22 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-16 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- version_requirements: *id001
31
- name: shoulda
32
- prerelease: false
33
- type: :development
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- none: false
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- hash: 31
41
- segments:
42
- - 3
43
- - 12
44
- version: "3.12"
45
- version_requirements: *id002
46
- name: rdoc
47
- prerelease: false
48
- type: :development
49
- - !ruby/object:Gem::Dependency
50
- requirement: &id003 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ~>
54
- - !ruby/object:Gem::Version
55
- hash: 23
56
- segments:
57
- - 1
58
- - 0
59
- - 0
60
- version: 1.0.0
61
- version_requirements: *id003
62
- name: bundler
63
- prerelease: false
64
- type: :development
65
- - !ruby/object:Gem::Dependency
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ~>
70
- - !ruby/object:Gem::Version
71
- hash: 49
72
- segments:
73
- - 1
74
- - 8
75
- - 3
76
- version: 1.8.3
77
- version_requirements: *id004
78
- name: jeweler
79
- prerelease: false
80
- type: :development
81
- - !ruby/object:Gem::Dependency
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
91
- version_requirements: *id005
92
- name: rcov
93
- prerelease: false
94
- type: :development
18
+ date: 2012-02-21 00:00:00 Z
19
+ dependencies: []
20
+
95
21
  description: this gem makes you post times in human readable for, like "one minute ago" instead of the exact time.
96
22
  email: frederikreich@googlemail.com
97
23
  executables: []
98
24
 
99
25
  extensions: []
100
26
 
101
- extra_rdoc_files:
102
- - LICENSE.txt
103
- - README.rdoc
27
+ extra_rdoc_files: []
28
+
104
29
  files:
105
- - .document
106
- - Gemfile
107
- - LICENSE.txt
108
- - README.rdoc
109
- - Rakefile
110
- - VERSION
111
30
  - lib/timeago.rb
112
- - test/helper.rb
113
- - test/test_timeago.rb
114
31
  homepage: http://github.com/FRickReich/timeago
115
- licenses:
116
- - MIT
32
+ licenses: []
33
+
117
34
  post_install_message:
118
35
  rdoc_options: []
119
36
 
@@ -143,6 +60,6 @@ rubyforge_project:
143
60
  rubygems_version: 1.8.11
144
61
  signing_key:
145
62
  specification_version: 3
146
- summary: a gem to convert time to human readable form.
63
+ summary: timeago
147
64
  test_files: []
148
65
 
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "rdoc", "~> 3.12"
11
- gem "bundler", "~> 1.0.0"
12
- gem "jeweler", "~> 1.8.3"
13
- gem "rcov", ">= 0"
14
- end
@@ -1,20 +0,0 @@
1
- Copyright (c) 2012 Frederik Reich
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.
@@ -1,31 +0,0 @@
1
- == timeago
2
-
3
- to use this gem, just require and run it, like this:
4
-
5
- = Example 1
6
-
7
- > require 'timeago'
8
- >
9
- > time = Time.now - 60
10
- >
11
- > Timeago.readable(time)
12
-
13
- and it should output
14
- > one minute ago
15
-
16
- = Example 2
17
-
18
- > require 'timeago'
19
- >
20
- > time = Time.now - 13250
21
- >
22
- > Timeago.readable(time)
23
-
24
- this should output
25
- > 3 hours ago
26
-
27
- this can go up to 5 years ago, after that it will change to the exact date.
28
-
29
- == Copyright
30
-
31
- Copyright (c) 2012 Frederik Reich.
data/Rakefile DELETED
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "timeago"
18
- gem.homepage = "http://github.com/FRickReich/timeago"
19
- gem.license = "MIT"
20
- gem.summary = %Q{a gem to convert time to human readable form.}
21
- gem.description = %Q{this gem makes you post times in human readable for, like "one minute ago" instead of the exact time.}
22
- gem.email = "frederikreich@googlemail.com"
23
- gem.authors = ["Frederik Reich"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
41
- end
42
-
43
- task :default => :test
44
-
45
- require 'rdoc/task'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "timeago #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'timeago'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTimeago < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end