time_of_day_attr 0.0.1 → 0.0.2
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/config/locales/time_of_day.de.yml +1 -1
- data/lib/time_of_day_attr.rb +8 -11
- metadata +8 -8
- data/lib/time_of_day_attr/version.rb +0 -3
data/lib/time_of_day_attr.rb
CHANGED
@@ -26,28 +26,25 @@ module TimeOfDayAttr
|
|
26
26
|
def translate_format(format)
|
27
27
|
I18n.translate("time_of_day.formats.#{format}")
|
28
28
|
end
|
29
|
-
end
|
30
|
-
|
31
|
-
extend ActiveSupport::Concern
|
32
29
|
|
33
|
-
included do
|
34
30
|
end
|
35
31
|
|
36
|
-
|
37
|
-
|
32
|
+
ActiveRecord::Base.class_eval do
|
33
|
+
|
34
|
+
def self.time_of_day_attr *attrs
|
38
35
|
options = attrs.extract_options!
|
39
|
-
|
36
|
+
options[:formats] ||= [:default, :hour]
|
40
37
|
attrs.each do |attr|
|
41
38
|
define_method("#{attr}=") do |value|
|
42
39
|
if value.is_a?(String)
|
43
|
-
delocalized_values = formats.map { |format| TimeOfDayAttr.delocalize(value, format: format) rescue nil }
|
44
|
-
value = delocalized_values.first || send(attr)
|
40
|
+
delocalized_values = options[:formats].map { |format| TimeOfDayAttr.delocalize(value, format: format) rescue nil }
|
41
|
+
value = delocalized_values.compact.first || send(attr)
|
45
42
|
end
|
46
43
|
super(value)
|
47
44
|
end
|
48
45
|
end
|
49
46
|
end
|
47
|
+
|
50
48
|
end
|
51
|
-
end
|
52
49
|
|
53
|
-
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_of_day_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -43,9 +43,10 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description:
|
47
|
-
|
48
|
-
|
46
|
+
description: Adds time_of_day_attr to your models. Will try to convert time of day
|
47
|
+
to seconds since midnight when a string was set. Localized formats for conversation
|
48
|
+
can be added to your translation files. TimeOfDayAttr.localize converts seconds
|
49
|
+
since midnight back to time of day.
|
49
50
|
email:
|
50
51
|
- clemens_t@web.de
|
51
52
|
executables: []
|
@@ -55,7 +56,6 @@ files:
|
|
55
56
|
- config/locales/time_of_day.en.yml
|
56
57
|
- config/locales/time_of_day.de.yml
|
57
58
|
- lib/time_of_day_attr.rb
|
58
|
-
- lib/time_of_day_attr/version.rb
|
59
59
|
- MIT-LICENSE
|
60
60
|
- Rakefile
|
61
61
|
- README.rdoc
|
@@ -63,7 +63,7 @@ files:
|
|
63
63
|
- test/schema.rb
|
64
64
|
- test/test_helper.rb
|
65
65
|
- test/time_of_day_attr_test.rb
|
66
|
-
homepage:
|
66
|
+
homepage: https://github.com/clemenst/time_of_day_attr
|
67
67
|
licenses: []
|
68
68
|
post_install_message:
|
69
69
|
rdoc_options: []
|
@@ -86,7 +86,7 @@ rubyforge_project:
|
|
86
86
|
rubygems_version: 1.8.23
|
87
87
|
signing_key:
|
88
88
|
specification_version: 3
|
89
|
-
summary:
|
89
|
+
summary: Convert time of day to seconds since midnight and back.
|
90
90
|
test_files:
|
91
91
|
- test/models/business_hour.rb
|
92
92
|
- test/schema.rb
|