time_of_day_attr 0.0.4 → 0.0.5

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 984b3d3213e41117ad551b328a807b7bc750e6c7
4
+ data.tar.gz: 696fe6fc73ef23a3ed4511491e33e2e393359293
5
+ SHA512:
6
+ metadata.gz: 5199b76eaf0664a91d071d35772d90fbb477a21a7a7ce764db5f974910b33957e8e30d0fac5176036dd68b8621bba68f1fb057918cc3a74b63e50983a3c84248
7
+ data.tar.gz: 39615de096cfdb717464e2152a61feb27bbdaab5f5915bcba36c3a975d8e5e399b775076c75a6fd2eef21469eebb1c18b48aa1f2762f73bfbff13880014a11b8
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # time_of_day_attr
2
+ [![Gem Version](https://badge.fury.io/rb/time_of_day_attr.png)](http://badge.fury.io/rb/time_of_day_attr) [![Code Climate](https://codeclimate.com/github/clemenst/time_of_day_attr.png)](https://codeclimate.com/github/clemenst/time_of_day_attr)
3
+
4
+ Convert time of day to seconds since midnight and back.
5
+
6
+ ## Installation
7
+
8
+ ```console
9
+ gem install time_of_day_attr
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ Define the time of day attributes:
15
+ ```ruby
16
+ class BusinessHour < ActiveRecord::Base
17
+ time_of_day_attr :opening, :closing
18
+ end
19
+ ```
20
+
21
+ Converts time of day to seconds since midnight when a string was set:
22
+ ```ruby
23
+ business_hour = BusinessHour.new(opening: '9:00', closing: '17:00')
24
+ business_hour.opening
25
+ => 32400
26
+ business_hour.closing
27
+ => 61200
28
+ ```
29
+
30
+ To convert back to time of day:
31
+ ```ruby
32
+ TimeOfDayAttr.l(business_hour.opening)
33
+ => '9:00'
34
+ TimeOfDayAttr.l(business_hour.closing)
35
+ => '17:00'
36
+ ```
37
+
38
+ You could also omit minutes at full hour:
39
+ ```ruby
40
+ TimeOfDayAttr.l(business_hour.opening, omit_minutes_at_full_hour: true)
41
+ => '9'
42
+ ```
43
+
44
+ ### Formats
45
+
46
+ The standard formats for conversation are 'default' and 'hour'.
47
+ ```yml
48
+ en:
49
+ time_of_day:
50
+ formats:
51
+ default: '%k:%M'
52
+ hour: '%k'
53
+ ```
54
+
55
+ You can overwrite them or use custom formats:
56
+ ```yml
57
+ en:
58
+ time_of_day:
59
+ formats:
60
+ custom: '%H-%M'
61
+ ```
62
+
63
+ Pass the formats you want for conversation:
64
+ ```ruby
65
+ class BusinessHour < ActiveRecord::Base
66
+ time_of_day_attr :opening, formats: [:custom]
67
+ end
68
+ ```
69
+
70
+ ```ruby
71
+ business_hour = BusinessHour.new(opening: '09-00')
72
+ business_hour.opening
73
+ => 32400
74
+ TimeOfDayAttr.l(business_hour.opening, format: :custom)
75
+ => '09-00'
76
+ ```
77
+
78
+ ### time of day field
79
+
80
+ To get a text field with the converted value:
81
+ ```erb
82
+ <%= form_for(business_hour) do |f| %>
83
+ <%= f.time_of_day_field(:opening) %>
84
+ <% end %>
85
+ ```
86
+
87
+ ## License
88
+
89
+ This project uses MIT-LICENSE
90
+
91
+ Copyright 2013 by Clemens Teichmann
92
+
93
+ Permission is hereby granted, free of charge, to any person obtaining
94
+ a copy of this software and associated documentation files (the
95
+ "Software"), to deal in the Software without restriction, including
96
+ without limitation the rights to use, copy, modify, merge, publish,
97
+ distribute, sublicense, and/or sell copies of the Software, and to
98
+ permit persons to whom the Software is furnished to do so, subject to
99
+ the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be
102
+ included in all copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
105
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
106
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
107
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
108
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
109
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
110
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ module TimeOfDayAttr
2
+ VERSION = '0.0.5'
3
+ end
data/test/test_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require 'active_record'
5
- require 'test/unit'
5
+ require 'minitest/autorun'
6
6
  require 'time_of_day_attr'
7
7
 
8
8
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
metadata CHANGED
@@ -1,46 +1,41 @@
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
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Clemens Teichmann
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.2.14
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.2.14
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Adds time_of_day_attr to your models. Will try to convert time of day
@@ -53,41 +48,40 @@ executables: []
53
48
  extensions: []
54
49
  extra_rdoc_files: []
55
50
  files:
56
- - config/locales/time_of_day.en.yml
51
+ - README.md
52
+ - Rakefile
57
53
  - config/locales/time_of_day.de.yml
54
+ - config/locales/time_of_day.en.yml
58
55
  - lib/time_of_day_attr.rb
59
56
  - lib/time_of_day_attr/active_record_ext.rb
60
57
  - lib/time_of_day_attr/form_builder_ext.rb
61
- - MIT-LICENSE
62
- - Rakefile
63
- - README.rdoc
58
+ - lib/time_of_day_attr/version.rb
64
59
  - test/models/business_hour.rb
65
60
  - test/schema.rb
66
61
  - test/test_helper.rb
67
62
  - test/time_of_day_attr_test.rb
68
63
  homepage: https://github.com/clemenst/time_of_day_attr
69
64
  licenses: []
65
+ metadata: {}
70
66
  post_install_message:
71
67
  rdoc_options: []
72
68
  require_paths:
73
69
  - lib
74
70
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
71
  requirements:
77
- - - ! '>='
72
+ - - ">="
78
73
  - !ruby/object:Gem::Version
79
74
  version: '0'
80
75
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
76
  requirements:
83
- - - ! '>='
77
+ - - ">="
84
78
  - !ruby/object:Gem::Version
85
79
  version: '0'
86
80
  requirements: []
87
81
  rubyforge_project:
88
- rubygems_version: 1.8.23
82
+ rubygems_version: 2.2.2
89
83
  signing_key:
90
- specification_version: 3
84
+ specification_version: 4
91
85
  summary: Convert time of day to seconds since midnight and back.
92
86
  test_files:
93
87
  - test/models/business_hour.rb
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2013 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = TimeOfDayAttr
2
-
3
- This project rocks and uses MIT-LICENSE.