Class: Dubs::Theme
- Inherits:
-
Object
- Object
- Dubs::Theme
- Defined in:
- lib/dubs/theme.rb
Instance Attribute Summary collapse
-
#default_category ⇒ Object
readonly
Returns the value of attribute default_category.
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #categories ⇒ Object
-
#initialize(data) ⇒ Theme
constructor
A new instance of Theme.
- #inspect ⇒ Object
- #nouns(category = nil) ⇒ Object
- #random_noun(category = nil) ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(data) ⇒ Theme
Returns a new instance of Theme.
7 8 9 10 11 12 |
# File 'lib/dubs/theme.rb', line 7 def initialize(data) @name = data["name"] @display_name = data["display_name"] @categories_data = data["categories"] @default_category = data["default_category"] end |
Instance Attribute Details
#default_category ⇒ Object (readonly)
Returns the value of attribute default_category.
5 6 7 |
# File 'lib/dubs/theme.rb', line 5 def default_category @default_category end |
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name.
5 6 7 |
# File 'lib/dubs/theme.rb', line 5 def display_name @display_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dubs/theme.rb', line 5 def name @name end |
Instance Method Details
#categories ⇒ Object
14 15 16 |
# File 'lib/dubs/theme.rb', line 14 def categories @categories_data.keys.map(&:to_sym) end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/dubs/theme.rb', line 33 def inspect "#<Dubs::Theme #{name} categories=#{categories}>" end |
#nouns(category = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/dubs/theme.rb', line 18 def nouns(category = nil) cat = (category || default_category).to_s @categories_data.fetch(cat) do raise CategoryNotFound, "Unknown category: #{cat} for theme #{name}. Available: #{categories.join(", ")}" end end |
#random_noun(category = nil) ⇒ Object
25 26 27 |
# File 'lib/dubs/theme.rb', line 25 def random_noun(category = nil) nouns(category).sample end |
#to_sym ⇒ Object
29 30 31 |
# File 'lib/dubs/theme.rb', line 29 def to_sym name.tr("-", "_").to_sym end |