Class: JAPI::Category

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

Overview

Category object with associated clues and a title.

Author:

  • Dean Silfen

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Category

Returns a new instance of Category.

Parameters:

  • options (Hash{String, Symbol => Fixnum, String}) (defaults to: {})

Options Hash (options):

  • :clues_count (Fixnum)

    amount of clues associated with this category

  • :id (Fixnum)

    category id

  • :clues (Array<Hash>)

    hashes for constructing clues. see JAPI::Clue

  • :title (String)

    the name of the category



11
12
13
14
15
16
# File 'lib/japi/category.rb', line 11

def initialize(options = {})
  @options = options
  if @options["clues"]
    @options["clues"] = @options["clues"].map { |clue| Clue.new(clue) }
  end
end

Instance Method Details

#category_idFixnum

Returns id of the category.

Returns:

  • (Fixnum)

    id of the category



24
25
26
# File 'lib/japi/category.rb', line 24

def category_id
  @options["id"]
end

#cluesArray<Clue>

Returns array of clues associated with a Category.

Returns:

  • (Array<Clue>)

    array of clues associated with a Category



34
35
36
37
# File 'lib/japi/category.rb', line 34

def clues
  return @options["clues"] unless @options["clues"].nil?
  @options["clues"] = Trebek.category(category_id).clues
end

#clues_countFixnum

Returns amount of clues associated with this category.

Returns:

  • (Fixnum)

    amount of clues associated with this category



29
30
31
# File 'lib/japi/category.rb', line 29

def clues_count
  @options["clues_count"]
end

#titleString

Returns title of the category.

Returns:

  • (String)

    title of the category



19
20
21
# File 'lib/japi/category.rb', line 19

def title
  @options["title"]
end