Class: LighterpackParser::Category

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

Overview

Represents a category from a Lighterpack list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description: nil, items: []) ⇒ Category

Returns a new instance of Category.

Parameters:

  • name (String)

    The name of the category

  • description (String, nil) (defaults to: nil)

    Optional description

  • items (Array<Item>) (defaults to: [])

    Array of items in this category



15
16
17
18
19
# File 'lib/lighterpack_parser/category.rb', line 15

def initialize(name:, description: nil, items: [])
  @name = name
  @description = description
  @items = items
end

Instance Attribute Details

#descriptionString? (readonly)

Optional description of the category

Returns:

  • (String, nil)

    the current value of description



9
10
11
# File 'lib/lighterpack_parser/category.rb', line 9

def description
  @description
end

#itemsArray<Item> (readonly)

Array of items in this category

Returns:

  • (Array<Item>)

    the current value of items



9
10
11
# File 'lib/lighterpack_parser/category.rb', line 9

def items
  @items
end

#nameString (readonly)

The name of the category

Returns:

  • (String)

    the current value of name



9
10
11
# File 'lib/lighterpack_parser/category.rb', line 9

def name
  @name
end

Instance Method Details

#to_hHash

Convert to hash for backward compatibility

Returns:

  • (Hash)

    Hash representation of the category



23
24
25
26
27
28
29
# File 'lib/lighterpack_parser/category.rb', line 23

def to_h
  {
    name: name,
    description: description,
    items: items.map(&:to_h)
  }
end