date_from_params 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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/date_from_params.gemspec +27 -0
- data/lib/date_from_params.rb +45 -0
- data/lib/date_from_params/version.rb +3 -0
- data/spec/date_from_params_spec.rb +144 -0
- data/spec/spec_helper.rb +20 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjU0YTVjNWJkN2E1MTU0ZTExNTE1Y2ZiNmE0MGM5ODZmMmQzNTI1ZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTRjNDExMTg3YWJhZjU1NTgwN2ExMmIxNDRkZGE1OWM5ZmQ4YmMwMg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDUxMWNiZmZmNjZkZjVjYjdhOTJlNzNjYTFhZDI4OTI0MmY5Nzc3YjQxODI3
|
10
|
+
YzI3OTRiZWNjNThkNmU2MzQxODhhN2U4OWQwYjRhMDkyNGMzM2QxMDczYTFj
|
11
|
+
MWM3YjU1ZDhiNWQ3MDQ2YmYyODhiYWNkYjU2NjI4MzEzZDBlMjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGQyN2I3MDMwMjFhY2U3MTQ5Mjc0Y2U2MWE4YmQyYmIxY2MyNDY2MTBiZmVl
|
14
|
+
ZGQxM2QzNWI4M2U0NGJjOGQ2ZjJjYTIwZTFhYTZjNTM5MDA4YWQwZjA0ZGVm
|
15
|
+
ODA3NTBjYmRmYmFhM2YxNTliMzJhYmRjZmI5YmNkMWE1NzkwNDk=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Pavel Astraukh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# DateFromParams
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'date_from_params'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install date_from_params
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'date_from_params/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "date_from_params"
|
8
|
+
spec.version = DateFromParams::VERSION
|
9
|
+
spec.authors = ["Pavel Astraukh"]
|
10
|
+
spec.email = ["paladin111333@yandex.ru"]
|
11
|
+
spec.description = %q{Gem for fetching date or datetime from rails view helpers}
|
12
|
+
spec.summary = %q{Gem provides functionality for fetching date/datetime from
|
13
|
+
rails view helpers such as date_select, datetime_select,
|
14
|
+
select_date and select_datetime}
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency 'activesupport', '~> 3.2'
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "date_from_params/version"
|
2
|
+
|
3
|
+
module DateFromParams
|
4
|
+
def date_from_select_date(key, params)
|
5
|
+
date_params = params[key]
|
6
|
+
|
7
|
+
begin
|
8
|
+
Date.civil(*[:year, :month, :day].map { |k| date_params[k].to_i unless (date_params[k] == nil || date_params[k] == "") })
|
9
|
+
rescue
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def datetime_from_select_datetime(key, params)
|
15
|
+
datetime_params = params[key]
|
16
|
+
|
17
|
+
begin
|
18
|
+
DateTime.civil(*[:year, :month, :day, :hour, :minute].map { |k| datetime_params[k].to_i unless (datetime_params[k] == nil || datetime_params[k] == "") })
|
19
|
+
rescue
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def date_from_date_select(key, params)
|
25
|
+
date_params = params.select { |k,v| k.include?(key.to_s) }
|
26
|
+
|
27
|
+
begin
|
28
|
+
Date.civil(*date_params.values.map { |v| v.to_i unless (v == nil || v == "") })
|
29
|
+
rescue
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def datetime_from_datetime_select(key, params)
|
35
|
+
datetime_params = params.select { |k,v| k.include?(key.to_s) }
|
36
|
+
|
37
|
+
begin
|
38
|
+
DateTime.civil(*datetime_params.values.map { |v| v.to_i unless (v == nil || v == "") })
|
39
|
+
rescue
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
extend self
|
45
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DateFromParams do
|
4
|
+
describe '#date_from_date_select' do
|
5
|
+
context 'with valid params' do
|
6
|
+
subject(:params) do
|
7
|
+
HashWithIndifferentAccess.new({
|
8
|
+
"finished_at(1i)"=>"2010",
|
9
|
+
"finished_at(2i)"=>"2",
|
10
|
+
"finished_at(3i)"=>"3"
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it do
|
15
|
+
DateFromParams.date_from_date_select(:finished_at, params).should eq Date.civil(2010, 2, 3)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with unvalid params' do
|
20
|
+
subject(:params) do
|
21
|
+
HashWithIndifferentAccess.new({
|
22
|
+
"finished_at(1i)"=>"",
|
23
|
+
"finished_at(2i)"=>"2",
|
24
|
+
"finished_at(3i)"=>"3"
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
it do
|
29
|
+
DateFromParams.date_from_date_select(:finished_at, params).should be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe '#datetime_from_datetime_select' do
|
36
|
+
context 'with valid params' do
|
37
|
+
subject(:params) do
|
38
|
+
HashWithIndifferentAccess.new({
|
39
|
+
"finished_at(1i)"=>"2010",
|
40
|
+
"finished_at(2i)"=>"2",
|
41
|
+
"finished_at(3i)"=>"3",
|
42
|
+
"finished_at(4i)"=>"12",
|
43
|
+
"finished_at(5i)"=>"10"
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
it do
|
48
|
+
DateFromParams.datetime_from_datetime_select(:finished_at, params).should eq DateTime.civil(2010, 2, 3, 12, 10)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with unvalid params' do
|
53
|
+
subject(:params) do
|
54
|
+
HashWithIndifferentAccess.new({
|
55
|
+
"finished_at(1i)"=>"2010",
|
56
|
+
"finished_at(2i)"=>"2",
|
57
|
+
"finished_at(3i)"=>"3",
|
58
|
+
"finished_at(4i)"=>"12",
|
59
|
+
"finished_at(5i)"=>""
|
60
|
+
})
|
61
|
+
end
|
62
|
+
|
63
|
+
it do
|
64
|
+
DateFromParams.datetime_from_datetime_select(:finished_at, params).should be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#date_from_select_date' do
|
70
|
+
context 'with valid params' do
|
71
|
+
subject(:params) do
|
72
|
+
HashWithIndifferentAccess.new({
|
73
|
+
"finished_at"=>
|
74
|
+
{
|
75
|
+
"year"=>"2010",
|
76
|
+
"month"=>"1",
|
77
|
+
"day"=>"2"
|
78
|
+
}
|
79
|
+
})
|
80
|
+
end
|
81
|
+
|
82
|
+
it do
|
83
|
+
DateFromParams.date_from_select_date(:finished_at, params).should eq Date.civil(2010, 1, 2)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with unvalid params' do
|
88
|
+
subject(:params) do
|
89
|
+
HashWithIndifferentAccess.new({
|
90
|
+
"finished_at"=>
|
91
|
+
{
|
92
|
+
"year"=>"",
|
93
|
+
"month"=>"1",
|
94
|
+
"day"=>"2"
|
95
|
+
}
|
96
|
+
})
|
97
|
+
end
|
98
|
+
|
99
|
+
it do
|
100
|
+
DateFromParams.date_from_select_date(:finished_at, params).should be_nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#datetime_from_select_datetime' do
|
106
|
+
context 'with valid params' do
|
107
|
+
subject(:params) do
|
108
|
+
HashWithIndifferentAccess.new({
|
109
|
+
"finished_at"=>
|
110
|
+
{
|
111
|
+
"year"=>"2010",
|
112
|
+
"month"=>"1",
|
113
|
+
"day"=>"2",
|
114
|
+
"hour"=>"12",
|
115
|
+
"minute"=>"10"
|
116
|
+
}
|
117
|
+
})
|
118
|
+
end
|
119
|
+
|
120
|
+
it do
|
121
|
+
DateFromParams.datetime_from_select_datetime(:finished_at, params).should eq DateTime.civil(2010, 1, 2, 12, 10)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'with unvalid params' do
|
126
|
+
subject(:params) do
|
127
|
+
HashWithIndifferentAccess.new({
|
128
|
+
"finished_at"=>
|
129
|
+
{
|
130
|
+
"year"=>"",
|
131
|
+
"month"=>"1",
|
132
|
+
"day"=>"2",
|
133
|
+
"hour"=>"12",
|
134
|
+
"minute"=>"10"
|
135
|
+
}
|
136
|
+
})
|
137
|
+
end
|
138
|
+
|
139
|
+
it do
|
140
|
+
DateFromParams.datetime_from_select_datetime(:finished_at, params).should be_nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require_relative '../lib/date_from_params'
|
8
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: date_from_params
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Astraukh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Gem for fetching date or datetime from rails view helpers
|
70
|
+
email:
|
71
|
+
- paladin111333@yandex.ru
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- date_from_params.gemspec
|
83
|
+
- lib/date_from_params.rb
|
84
|
+
- lib/date_from_params/version.rb
|
85
|
+
- spec/date_from_params_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Gem provides functionality for fetching date/datetime from rails view helpers
|
111
|
+
such as date_select, datetime_select, select_date and select_datetime
|
112
|
+
test_files:
|
113
|
+
- spec/date_from_params_spec.rb
|
114
|
+
- spec/spec_helper.rb
|