Class: Eso::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/eso/filter.rb

Defined Under Namespace

Classes: FilterItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, items: []) ⇒ Eso::Filter

Constructor for Filter.

Parameters:

  • type (String)

    The type of filter this is. They are based on the service this filter exists in. These are defined in Eso::Filters which reside in the respective service they are related to.

  • items (Array) (defaults to: [])

    Array of filters of this type



15
16
17
18
# File 'lib/eso/filter.rb', line 15

def initialize(type:, items: [])
 @type = type
 @filter_items = items
end

Instance Attribute Details

#filter_itemsObject

These are the individual filter items



7
8
9
# File 'lib/eso/filter.rb', line 7

def filter_items
  @filter_items
end

#typeObject

These are defined in Eso::Filters which reside in the respective service they are related to.



4
5
6
# File 'lib/eso/filter.rb', line 4

def type
  @type
end

Instance Method Details

#<<(filter_item) ⇒ Object

Append a filter_item later



21
22
23
# File 'lib/eso/filter.rb', line 21

def <<(filter_item)
  @filter_items << filter_item
end

#to_hashObject Also known as: to_h



29
30
31
32
33
34
35
36
# File 'lib/eso/filter.rb', line 29

def to_hash
  hash = {}
  hash[@type.to_sym] = {
    valueClass: 'Array',
    items: @filter_items.map{|item| item.to_hash}
  }
  hash
end

#to_jsonObject



25
26
27
# File 'lib/eso/filter.rb', line 25

def to_json
  self.to_hash.to_json
end