Class: Category

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Category

Returns a new instance of Category.



6
7
8
9
10
11
12
# File 'lib/category.rb', line 6

def initialize(attributes)
  @title = attributes[:title]
  @parent = attributes[:parents]
  @filter = attributes[:alias]
  @restaurants = []
  @@all << self
end

Instance Attribute Details

#filterObject

Returns the value of attribute filter.



2
3
4
# File 'lib/category.rb', line 2

def filter
  @filter
end

#parentsObject

Returns the value of attribute parents.



2
3
4
# File 'lib/category.rb', line 2

def parents
  @parents
end

#restaurantsObject

Returns the value of attribute restaurants.



2
3
4
# File 'lib/category.rb', line 2

def restaurants
  @restaurants
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/category.rb', line 2

def title
  @title
end

Class Method Details

.allObject



14
15
16
# File 'lib/category.rb', line 14

def self.all
  @@all
end

.find_by_title(title) ⇒ Object



33
34
35
# File 'lib/category.rb', line 33

def self.find_by_title(title)
  self.all.find {|category| category.title.downcase == title.downcase }
end

.get_category_listObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/category.rb', line 18

def self.get_category_list
  categories = CATEGORY_LIST.select do |category|
    category[:parents].include?("restaurants") &&
    !(category.has_key?(:country_blacklist) && category[:country_blacklist].include?("US")) &&
    !(category.has_key?(:country_whitelist) && !category[:country_whitelist].include?("US"))
  end
  categories += CATEGORY_LIST.select do |category|
    category[:parents].find {|parent| categories.map{|category| category[:alias]}.include?(parent)} &&
    !(category.has_key?(:country_blacklist) && category[:country_blacklist].include?("US")) &&
    !(category.has_key?(:country_whitelist) && !category[:country_whitelist].include?("US"))
  end
  categories.sort_by! {|category| category[:alias]}
  categories.map {|category| Category.new(category)}
end