hammock 0.5.0 → 0.5.1
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.
- data/History.txt +4 -0
- data/VERSION +1 -1
- data/hammock.gemspec +2 -2
- data/lib/hammock/monkey_patches/numeric.rb +40 -0
- data/lib/hammock.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/hammock.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hammock}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Hoskings"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-28}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{ben@hoskings.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -20,6 +20,46 @@ module Hammock
|
|
20
20
|
|
21
21
|
module InstanceMethods
|
22
22
|
|
23
|
+
def commas
|
24
|
+
if self < 1000
|
25
|
+
self
|
26
|
+
else
|
27
|
+
whole, fract = self.to_s.split('.')
|
28
|
+
[ whole.reverse.scan(/\d{1,3}/).join(',').reverse, fract ].squash.join('.')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Round the value to num significant figures
|
33
|
+
def sigfigs num, opts = {}
|
34
|
+
shift = 10 ** (num - self.floor.to_s.length) # preserve this many digits after the decimal place, ** 10 for scaling
|
35
|
+
val = (self * shift).round * 1.0 / shift # shift decimal place, chop off remainder, shift back
|
36
|
+
val = val.floor if opts[:drop_trailing_zeros] && (val == val.floor) # drop '.0' if requested and present
|
37
|
+
val # done
|
38
|
+
end
|
39
|
+
|
40
|
+
def xsecs
|
41
|
+
value = self.abs
|
42
|
+
past = (self < 0)
|
43
|
+
|
44
|
+
if value == 0
|
45
|
+
'now'
|
46
|
+
elsif value === 1...60
|
47
|
+
"less than a minute#{' ago' if past}"
|
48
|
+
else
|
49
|
+
case value / 20
|
50
|
+
when 0...3600; value /= 60; unit = 'minute'
|
51
|
+
when 3600...(3600*24); value /= 3600; unit = 'hour'
|
52
|
+
when (3600*24)...(3600*24*7); value /= (3600*24); unit = 'day'
|
53
|
+
when (3600*24*7)...(3600*24*30); value /= (3600*24*7); unit = 'week'
|
54
|
+
when (3600*24*30)...(3600*24*365); value /= (3600*24*30); unit = 'month'
|
55
|
+
else value /= (3600*24*365); unit = 'year'
|
56
|
+
end
|
57
|
+
|
58
|
+
value = 1 if value == 0
|
59
|
+
"#{value.commas} #{unit}#{'s' unless value == 1}#{' ago' if past}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
23
63
|
end
|
24
64
|
end
|
25
65
|
end
|
data/lib/hammock.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Hoskings
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-28 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|