Class: LighterpackParser::List

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

Overview

Represents a Lighterpack list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description: nil, categories: []) ⇒ List

Returns a new instance of List.

Parameters:

  • name (String)

    The name of the list

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

    Optional description

  • categories (Array<Category>) (defaults to: [])

    Array of categories in this list



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

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

Instance Attribute Details

#categoriesArray<Category> (readonly)

Array of categories in this list

Returns:

  • (Array<Category>)

    the current value of categories



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

def categories
  @categories
end

#descriptionString? (readonly)

Optional description of the list

Returns:

  • (String, nil)

    the current value of description



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

def description
  @description
end

#nameString (readonly)

The name of the list

Returns:

  • (String)

    the current value of name



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

def name
  @name
end

Instance Method Details

#to_hHash

Convert to hash for backward compatibility

Returns:

  • (Hash)

    Hash representation of the list



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

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