date_formatter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/date_formatter.rb +40 -0
- metadata +67 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
module DateFormatter
|
2
|
+
|
3
|
+
FORMATTED_METHOD = /^formatted_(.+)$/
|
4
|
+
|
5
|
+
# ensure that respond_to? returns true if passed a valid formatted_method_name
|
6
|
+
def respond_to? method_name, some_random_argument = nil
|
7
|
+
return true if valid_formatted_method_name? method_name
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
# call strftime on the given date, with this class's strftime_date_string
|
12
|
+
def format_date value
|
13
|
+
value.strftime strftime_date_string
|
14
|
+
end
|
15
|
+
|
16
|
+
# generic date formatter
|
17
|
+
# called like formatted_method_name
|
18
|
+
# if your class responds to method_name, call format_date with it
|
19
|
+
def method_missing method_name, *args
|
20
|
+
if name = valid_formatted_method_name?(method_name)
|
21
|
+
value = send name
|
22
|
+
return format_date value
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# set a default value for strftime_date_string
|
29
|
+
# override this method in your class to customize the date format
|
30
|
+
def strftime_date_string
|
31
|
+
'%m/%d/%Y'
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def valid_formatted_method_name? method
|
37
|
+
return $1 if method.to_s =~ DateFormatter::FORMATTED_METHOD and respond_to?($1)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: date_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dev Fu!
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-28 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Format dates with a common format. Useful for making views and specs more readable.
|
23
|
+
email: info@devfu.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/date_formatter.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/devfu/date_formatter
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.7
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Simple date formatter using method_missing
|
66
|
+
test_files: []
|
67
|
+
|