pretty_stamps 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pretty/pretty.rb +122 -0
- data/lib/pretty/version.rb +3 -0
- data/lib/pretty.rb +6 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3064f5625f97131a5c6d860c77c79007c831c6a4
|
4
|
+
data.tar.gz: adc0446adba6f9281ca2e2cc4818a0918c4a4d2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c41e61828546201645d49251c34062770965306f03350ba5bcc296a035624ba7aff946ac34f576b22877a27fbdabb7353d5ae645f1f45820e256565a529246d7
|
7
|
+
data.tar.gz: 96c7cfcf55a64dd0be920102c8df5d92014333609e0ccc3f4e79d45a8254e501bd06df85485caeca1a6d8b212035f18e18b01569f3170f9e292d635b0811590e
|
@@ -0,0 +1,122 @@
|
|
1
|
+
|
2
|
+
class Time
|
3
|
+
# Clock argument for testing; defaults to Time
|
4
|
+
def pretty(clock=Time.now)
|
5
|
+
@expired = (clock-self).to_i
|
6
|
+
@today = clock.strftime('%A')
|
7
|
+
@created = self.to_time.strftime('%A')
|
8
|
+
|
9
|
+
@days = {
|
10
|
+
"Monday" => 1,
|
11
|
+
"Tuesday" => 2,
|
12
|
+
"Wednesday" => 3,
|
13
|
+
"Thursday" => 4,
|
14
|
+
"Friday" => 5,
|
15
|
+
"Saturday" => 6,
|
16
|
+
"Sunday" => 7
|
17
|
+
}
|
18
|
+
|
19
|
+
return just_now if just_now?
|
20
|
+
return a_second_ago if a_second_ago?
|
21
|
+
return seconds_ago if seconds_ago?
|
22
|
+
return a_minute_ago if a_minute_ago?
|
23
|
+
return minutes_ago if minutes_ago?
|
24
|
+
return an_hour_ago if an_hour_ago?
|
25
|
+
return today if is_today?
|
26
|
+
return yesterday if is_yesterday?
|
27
|
+
return this_week if this_week?
|
28
|
+
return last_week if last_week?
|
29
|
+
return datetimefiesta
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def just_now
|
34
|
+
'just now'
|
35
|
+
end
|
36
|
+
|
37
|
+
def just_now?
|
38
|
+
@expired == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def a_second_ago
|
42
|
+
'a second ago'
|
43
|
+
end
|
44
|
+
|
45
|
+
def a_second_ago?
|
46
|
+
@expired == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def seconds_ago
|
50
|
+
@expired.to_s+' seconds ago'
|
51
|
+
end
|
52
|
+
|
53
|
+
def seconds_ago?
|
54
|
+
@expired >= 2 && @expired <= 59
|
55
|
+
end
|
56
|
+
|
57
|
+
def a_minute_ago
|
58
|
+
'a minute ago'
|
59
|
+
end
|
60
|
+
|
61
|
+
def a_minute_ago?
|
62
|
+
@expired >= 60 && @expired <= 119 #120 = 2 minutes
|
63
|
+
end
|
64
|
+
|
65
|
+
def minutes_ago
|
66
|
+
(@expired/60).to_i.to_s+' minutes ago'
|
67
|
+
end
|
68
|
+
|
69
|
+
def minutes_ago?
|
70
|
+
@expired >= 120 && @expired <= 3599
|
71
|
+
end
|
72
|
+
|
73
|
+
def an_hour_ago
|
74
|
+
'an hour ago'
|
75
|
+
end
|
76
|
+
|
77
|
+
def an_hour_ago?
|
78
|
+
@expired >= 3600 && @expired <= 7199 # 3600 = 1 hour
|
79
|
+
end
|
80
|
+
|
81
|
+
def today
|
82
|
+
"Today at#{timeify}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def timeify
|
86
|
+
"#{self.to_time.strftime("%l:%M%p")}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def is_today?
|
90
|
+
@days[@today] - @days[@created] == 0 && @expired >= 7200 && @expired <= 82800
|
91
|
+
end
|
92
|
+
|
93
|
+
def yesterday
|
94
|
+
"Yesterday at#{timeify}"
|
95
|
+
end
|
96
|
+
|
97
|
+
def is_yesterday?
|
98
|
+
(@days[@today] - @days[@created] == 1 || @days[@created] + @days[@today] == 8) && @expired <= 172800
|
99
|
+
end
|
100
|
+
|
101
|
+
def this_week
|
102
|
+
"#{@created} at#{timeify}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def this_week?
|
106
|
+
@expired <= 604800 && @days[@today] - @days[@created] != 0
|
107
|
+
end
|
108
|
+
|
109
|
+
def last_week
|
110
|
+
"Last #{@created} at#{timeify}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def last_week?
|
114
|
+
@expired >= 518400 && @expired <= 1123200
|
115
|
+
end
|
116
|
+
|
117
|
+
def datetimefiesta
|
118
|
+
self.strftime("%A, %B %e at%l:%M%p")
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
data/lib/pretty.rb
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pretty_stamps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandra Wright, Brett Shollenberger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Humanizes datetime for Active Record objects.Ported from Rails by Alexandra
|
14
|
+
Wright, intended for use in the Sinatra microframework
|
15
|
+
email:
|
16
|
+
- superbiscuit@gmail.com, brett.shollenberger@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/pretty.rb
|
22
|
+
- lib/pretty/pretty.rb
|
23
|
+
- lib/pretty/version.rb
|
24
|
+
homepage: https://github.com/f3mshep/hublot
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.8
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Adds datetime humanization to Active Record objects.
|
48
|
+
test_files: []
|