Class: Category
- Inherits:
-
Object
- Object
- Category
- Defined in:
- lib/category.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#restaurants ⇒ Object
Returns the value of attribute restaurants.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Category
constructor
A new instance of Category.
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
#filter ⇒ Object
Returns the value of attribute filter.
2 3 4 |
# File 'lib/category.rb', line 2 def filter @filter end |
#parents ⇒ Object
Returns the value of attribute parents.
2 3 4 |
# File 'lib/category.rb', line 2 def parents @parents end |
#restaurants ⇒ Object
Returns the value of attribute restaurants.
2 3 4 |
# File 'lib/category.rb', line 2 def restaurants @restaurants end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/category.rb', line 2 def title @title end |
Class Method Details
.all ⇒ Object
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_list ⇒ Object
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 |