Class: LighterpackParser::Item

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

Overview

Represents a single item from a Lighterpack list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, weight:, total_weight:, quantity:, description: nil, image_url: nil, consumable: false, total_consumable_weight: nil, worn: false, worn_quantity: nil, total_worn_weight: nil) ⇒ Item

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength

Parameters:

  • name (String)

    The name of the item

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

    Optional description

  • weight (Float)

    Weight per item in grams

  • total_weight (Float)

    Total weight (weight * quantity) in grams

  • quantity (Integer)

    Number of items

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

    Optional URL to item image

  • consumable (Boolean) (defaults to: false)

    Whether the item is consumable

  • total_consumable_weight (Float, nil) (defaults to: nil)

    Total consumable weight if consumable

  • worn (Boolean) (defaults to: false)

    Whether the item is worn

  • worn_quantity (Integer, nil) (defaults to: nil)

    Number of worn items (1 if worn)

  • total_worn_weight (Float, nil) (defaults to: nil)

    Total worn weight if worn



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lighterpack_parser/item.rb', line 34

def initialize(name:, weight:, total_weight:, quantity:, description: nil,
               image_url: nil, consumable: false, total_consumable_weight: nil,
               worn: false, worn_quantity: nil, total_worn_weight: nil)
  @name = name
  @description = description
  @weight = weight
  @total_weight = total_weight
  @quantity = quantity
  @image_url = image_url
  @consumable = consumable
  @total_consumable_weight = total_consumable_weight
  @worn = worn
  @worn_quantity = worn_quantity
  @total_worn_weight = total_worn_weight
end

Instance Attribute Details

#consumableBoolean (readonly)

Whether the item is consumable

Returns:

  • (Boolean)

    the current value of consumable



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def consumable
  @consumable
end

#descriptionString? (readonly)

Optional description of the item

Returns:

  • (String, nil)

    the current value of description



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def description
  @description
end

#image_urlString? (readonly)

Optional URL to item image

Returns:

  • (String, nil)

    the current value of image_url



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def image_url
  @image_url
end

#nameString (readonly)

The name of the item

Returns:

  • (String)

    the current value of name



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def name
  @name
end

#quantityInteger (readonly)

Number of items

Returns:

  • (Integer)

    the current value of quantity



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def quantity
  @quantity
end

#total_consumable_weightFloat? (readonly)

Total consumable weight (weight * quantity) if consumable, nil otherwise

Returns:

  • (Float, nil)

    the current value of total_consumable_weight



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def total_consumable_weight
  @total_consumable_weight
end

#total_weightFloat (readonly)

Total weight (weight * quantity) in grams

Returns:

  • (Float)

    the current value of total_weight



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def total_weight
  @total_weight
end

#total_worn_weightFloat? (readonly)

Total worn weight (weight * 1) if worn, nil otherwise

Returns:

  • (Float, nil)

    the current value of total_worn_weight



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def total_worn_weight
  @total_worn_weight
end

#weightFloat (readonly)

Weight per item in grams

Returns:

  • (Float)

    the current value of weight



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def weight
  @weight
end

#wornBoolean (readonly)

Whether the item is worn

Returns:

  • (Boolean)

    the current value of worn



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def worn
  @worn
end

#worn_quantityInteger? (readonly)

Number of worn items (always 1 if worn, nil otherwise)

Returns:

  • (Integer, nil)

    the current value of worn_quantity



18
19
20
# File 'lib/lighterpack_parser/item.rb', line 18

def worn_quantity
  @worn_quantity
end

Instance Method Details

#consumable?Boolean

Returns Whether the item is consumable.

Returns:

  • (Boolean)

    Whether the item is consumable



55
# File 'lib/lighterpack_parser/item.rb', line 55

def consumable? = consumable

#to_hHash

Convert to hash

Returns:

  • (Hash)

    Hash representation of the item



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lighterpack_parser/item.rb', line 60

def to_h
  {
    name: name, description: description,
    weight: weight, total_weight: total_weight,
    quantity: quantity,
    image_url: image_url,
    consumable: consumable,
    total_consumable_weight: total_consumable_weight,
    worn: worn, worn_quantity: worn_quantity,
    total_worn_weight: total_worn_weight
  }
end

#worn?Boolean

Returns Whether the item is worn.

Returns:

  • (Boolean)

    Whether the item is worn



52
# File 'lib/lighterpack_parser/item.rb', line 52

def worn? = worn