Class: Dubs::Theme

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_categoryObject (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_nameObject (readonly)

Returns the value of attribute display_name.



5
6
7
# File 'lib/dubs/theme.rb', line 5

def display_name
  @display_name
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/dubs/theme.rb', line 5

def name
  @name
end

Instance Method Details

#categoriesObject



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

def categories
  @categories_data.keys.map(&:to_sym)
end

#inspectObject



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_symObject



29
30
31
# File 'lib/dubs/theme.rb', line 29

def to_sym
  name.tr("-", "_").to_sym
end