hammock 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.5.1 2009-10-28
2
+ Added Numeric#commas, #sigfigs and #xsecs.
3
+
4
+
1
5
  == 0.5.0 2009-10-27
2
6
  Redesigned ajaxinate implementation - instead of rendering JS separately for every link, use one generic method and a link map to store details for each link.
3
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
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.0"
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-27}
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
@@ -4,7 +4,7 @@ require 'ambition'
4
4
  require 'ambition/adapters/active_record'
5
5
 
6
6
  module Hammock
7
- VERSION = '0.4.2'
7
+ VERSION = '0.5.1'
8
8
  IncludeTarget = ActionController::Base
9
9
 
10
10
  def self.included base # :nodoc:
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.0
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-27 00:00:00 +11:00
12
+ date: 2009-10-28 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency