Class: Emojidex::Categories
- Inherits:
-
Object
- Object
- Emojidex::Categories
- Defined in:
- lib/emojidex/categories.rb
Overview
Holds a master list of categories
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
Instance Method Summary collapse
-
#collect(&block) ⇒ Object
collect override to map each functionality to the categories hash.
-
#each(&block) ⇒ Object
each override to map each functionality to the categories hash.
-
#initialize(categories_json = nil) ⇒ Categories
constructor
A new instance of Categories.
-
#load_categories(json) ⇒ Object
loads categories from a JSON hash object / JSON text.
-
#load_standard_categories ⇒ Object
loads standard categories local to the emojidex package *automatically called on initialize if no options are passed.
-
#map(&block) ⇒ Object
map override to map each functionality to the categories hash.
-
#select(&block) ⇒ Object
select override to map select functionality to the categories hash.
Constructor Details
#initialize(categories_json = nil) ⇒ Categories
8 9 10 11 12 13 14 |
# File 'lib/emojidex/categories.rb', line 8 def initialize(categories_json = nil) if categories_json load_categories(categories_json) else load_standard_categories end end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
6 7 8 |
# File 'lib/emojidex/categories.rb', line 6 def categories @categories end |
Instance Method Details
#collect(&block) ⇒ Object
collect override to map each functionality to the categories hash
32 33 34 |
# File 'lib/emojidex/categories.rb', line 32 def collect(&block) @categories.values.collect(&block) end |
#each(&block) ⇒ Object
each override to map each functionality to the categories hash
17 18 19 |
# File 'lib/emojidex/categories.rb', line 17 def each(&block) @categories.values.each(&block) end |
#load_categories(json) ⇒ Object
loads categories from a JSON hash object / JSON text
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/emojidex/categories.rb', line 37 def load_categories(json) raw = JSON.parse(json, symbolize_names: true) raw = raw[:categories] @categories ||= {} raw.each do |category_info| category = Emojidex::Category.new category_info @categories[category.code.to_sym] = category end end |
#load_standard_categories ⇒ Object
loads standard categories local to the emojidex package *automatically called on initialize if no options are passed
50 51 52 53 |
# File 'lib/emojidex/categories.rb', line 50 def load_standard_categories load_categories(IO.read( File.('../../../emoji/categories.json', __FILE__))) end |
#map(&block) ⇒ Object
map override to map each functionality to the categories hash
27 28 29 |
# File 'lib/emojidex/categories.rb', line 27 def map(&block) @categories.values.map(&block) end |
#select(&block) ⇒ Object
select override to map select functionality to the categories hash
22 23 24 |
# File 'lib/emojidex/categories.rb', line 22 def select(&block) @categories.values.select(&block) end |