yourub 1.0.3 → 1.0.4
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 +4 -4
- data/lib/yourub/validator.rb +19 -5
- data/lib/yourub/version.rb +1 -1
- data/spec/validator_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a837f36e2f88084e6c3cef0ebf1ae93bf2bb856
|
4
|
+
data.tar.gz: a65082a176e99de6ef63b21faf295b7f0aea3c50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dda7c152233c2997df0a41d9f55f539132f0cee15c1e81a7eb5f7f9d265f548e302771825a534b67e402c07e18afd3346d64eac6e4c69620a68ea1a7add178b
|
7
|
+
data.tar.gz: d107046ec38b048343ff2825ed1e2c208c7a1c7bb2ef21514876f7f3affb0337256f1c49ad2d4a804b8c1d638beaf7cbac9834183b031ff5465548285c27d08a
|
data/lib/yourub/validator.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Yourub
|
2
2
|
module Validator
|
3
3
|
class << self
|
4
|
-
#attr_reader :videos, :countrys, :categories
|
5
4
|
|
6
5
|
DEFAULT_COUNTRY = "US" #if not given, a country it's necessary to retrieve a categories list
|
7
6
|
COUNTRIES = [
|
@@ -13,8 +12,8 @@ module Yourub
|
|
13
12
|
MINIMUM_PARAMS = [:country, :category, :query, :id]
|
14
13
|
|
15
14
|
def confirm(criteria)
|
16
|
-
|
17
|
-
|
15
|
+
valid_format?(criteria)
|
16
|
+
@criteria = symbolize_keys(criteria)
|
18
17
|
remove_empty_and_non_valid_params
|
19
18
|
minimum_param_present?
|
20
19
|
|
@@ -30,6 +29,21 @@ module Yourub
|
|
30
29
|
COUNTRIES
|
31
30
|
end
|
32
31
|
|
32
|
+
def symbolize_keys(hash)
|
33
|
+
hash.inject({}){|result, (key, value)|
|
34
|
+
new_key = case key
|
35
|
+
when String then key.to_sym
|
36
|
+
else key
|
37
|
+
end
|
38
|
+
new_value = case value
|
39
|
+
when Hash then symbolize_keys(value)
|
40
|
+
else value
|
41
|
+
end
|
42
|
+
result[new_key] = new_value
|
43
|
+
result
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
33
47
|
def remove_empty_and_non_valid_params
|
34
48
|
@criteria.keep_if{|k,v| ( (VALID_PARAMS.include? k) && (v.size > 0)) }
|
35
49
|
end
|
@@ -61,10 +75,10 @@ module Yourub
|
|
61
75
|
return categories
|
62
76
|
end
|
63
77
|
|
64
|
-
def valid_format?
|
78
|
+
def valid_format?(criteria)
|
65
79
|
raise ArgumentError.new(
|
66
80
|
"give an hash as search criteria"
|
67
|
-
) unless(
|
81
|
+
) unless( criteria.is_a? Hash )
|
68
82
|
end
|
69
83
|
|
70
84
|
def minimum_param_present?
|
data/lib/yourub/version.rb
CHANGED
data/spec/validator_spec.rb
CHANGED
@@ -5,6 +5,14 @@ describe Yourub::Validator do
|
|
5
5
|
|
6
6
|
context "passing an hash containing the search criteria" do
|
7
7
|
context "with some valid criteria" do
|
8
|
+
|
9
|
+
context "no matter if the crteria has old 'key' => 'val' or key: val sintax" do
|
10
|
+
let(:criteria) { {"country" => 'US', "category" => 'Sport'} }
|
11
|
+
it "return criteria including nation but excluding the city" do
|
12
|
+
expect(subject).to eq({country: ['US'], category: 'Sport'})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
8
16
|
context "with valid nation but unknown parameter city" do
|
9
17
|
let(:criteria) { {country: 'US', city: 'Berlin'} }
|
10
18
|
it "return criteria including nation but excluding the city" do
|