Class: Refinuri::Base::FilterSet

Inherits:
Object
  • Object
show all
Defined in:
lib/refinuri/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ FilterSet

Returns a new instance of FilterSet.

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/refinuri/base.rb', line 5

def initialize(hash)
  raise ArgumentError, "Argument must be a Hash", caller unless hash.is_a?(Hash)
  @filters = Hash.new
  modify_filters(hash)
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



4
5
6
# File 'lib/refinuri/base.rb', line 4

def filters
  @filters
end

Instance Method Details

#[](filter_name) ⇒ Object



18
19
20
# File 'lib/refinuri/base.rb', line 18

def [](filter_name)
  @filters[filter_name]# && @filters[filter_name].value
end

#merge!(hash) ⇒ Object



11
12
13
14
15
16
# File 'lib/refinuri/base.rb', line 11

def merge!(hash)
  hash[:update] ||= Hash.new
  hash[:update].merge!(extract_implicit_filters(hash))
  hash.each { |key,value| modify_filters(value,key) }
  return self
end

#to_hObject



22
23
24
25
26
# File 'lib/refinuri/base.rb', line 22

def to_h
  filters = Hash.new
  @filters.each { |key,value| filters[key] = value.value }
  return filters
end

#to_urlObject



28
29
30
31
32
33
34
# File 'lib/refinuri/base.rb', line 28

def to_url
  string_array = Array.new
  @filters.each do |name,filter_obj|
    string_array << "#{name}:#{filter_obj.to_s}"
  end
  return string_array.join(';')
end