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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a0be92cbe99be4b3c73651130982a82f7dce8f4
4
- data.tar.gz: 1e638899809319c25f2f7c313018b2e50dfa226e
3
+ metadata.gz: 5a837f36e2f88084e6c3cef0ebf1ae93bf2bb856
4
+ data.tar.gz: a65082a176e99de6ef63b21faf295b7f0aea3c50
5
5
  SHA512:
6
- metadata.gz: 93d008ead18d4f0f96632f4cb56d4fa2a7ad67214bc89e02cc0cd5ceefaa90e715417ea73db0138405165c07748aae4d51ce197f2f8148fe9433ab43717142a0
7
- data.tar.gz: 56df27790fa3eb57c651ccf76d3fab867aa395148a2cbf96a0a47192c729e6b65b1b16ce7cf18328c33086b813210845580f106ea0ca31a4143fbbf57b3a6394
6
+ metadata.gz: 4dda7c152233c2997df0a41d9f55f539132f0cee15c1e81a7eb5f7f9d265f548e302771825a534b67e402c07e18afd3346d64eac6e4c69620a68ea1a7add178b
7
+ data.tar.gz: d107046ec38b048343ff2825ed1e2c208c7a1c7bb2ef21514876f7f3affb0337256f1c49ad2d4a804b8c1d638beaf7cbac9834183b031ff5465548285c27d08a
@@ -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
- @criteria = criteria
17
- valid_format?
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( @criteria.is_a? Hash )
81
+ ) unless( criteria.is_a? Hash )
68
82
  end
69
83
 
70
84
  def minimum_param_present?
@@ -1,6 +1,6 @@
1
1
  module Yourub
2
2
  MAJOR = 1
3
3
  MINOR = 0
4
- PATCH = 3
4
+ PATCH = 4
5
5
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
6
6
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yourub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davide Prati