Class: LighterpackParser::Item
- Inherits:
-
Object
- Object
- LighterpackParser::Item
- Defined in:
- lib/lighterpack_parser/item.rb
Overview
Represents a single item from a Lighterpack list.
Instance Attribute Summary collapse
-
#consumable ⇒ Boolean
readonly
Whether the item is consumable.
-
#description ⇒ String?
readonly
Optional description of the item.
-
#image_url ⇒ String?
readonly
Optional URL to item image.
-
#name ⇒ String
readonly
The name of the item.
-
#quantity ⇒ Integer
readonly
Number of items.
-
#total_consumable_weight ⇒ Float?
readonly
Total consumable weight (weight * quantity) if consumable, nil otherwise.
-
#total_weight ⇒ Float
readonly
Total weight (weight * quantity) in grams.
-
#total_worn_weight ⇒ Float?
readonly
Total worn weight (weight * 1) if worn, nil otherwise.
-
#weight ⇒ Float
readonly
Weight per item in grams.
-
#worn ⇒ Boolean
readonly
Whether the item is worn.
-
#worn_quantity ⇒ Integer?
readonly
Number of worn items (always 1 if worn, nil otherwise).
Instance Method Summary collapse
-
#consumable? ⇒ Boolean
Whether the item is consumable.
-
#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
constructor
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength.
-
#to_h ⇒ Hash
Convert to hash.
-
#worn? ⇒ Boolean
Whether the item is worn.
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
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
#consumable ⇒ Boolean (readonly)
Whether the item is consumable
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def consumable @consumable end |
#description ⇒ String? (readonly)
Optional description of the item
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def description @description end |
#image_url ⇒ String? (readonly)
Optional URL to item image
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def image_url @image_url end |
#name ⇒ String (readonly)
The name of the item
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def name @name end |
#quantity ⇒ Integer (readonly)
Number of items
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def quantity @quantity end |
#total_consumable_weight ⇒ Float? (readonly)
Total consumable weight (weight * quantity) if consumable, nil otherwise
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def total_consumable_weight @total_consumable_weight end |
#total_weight ⇒ Float (readonly)
Total weight (weight * quantity) in grams
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def total_weight @total_weight end |
#total_worn_weight ⇒ Float? (readonly)
Total worn weight (weight * 1) if worn, nil otherwise
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def total_worn_weight @total_worn_weight end |
#weight ⇒ Float (readonly)
Weight per item in grams
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def weight @weight end |
#worn ⇒ Boolean (readonly)
Whether the item is worn
18 19 20 |
# File 'lib/lighterpack_parser/item.rb', line 18 def worn @worn end |
#worn_quantity ⇒ Integer? (readonly)
Number of worn items (always 1 if worn, nil otherwise)
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.
55 |
# File 'lib/lighterpack_parser/item.rb', line 55 def consumable? = consumable |
#to_h ⇒ Hash
Convert to hash
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.
52 |
# File 'lib/lighterpack_parser/item.rb', line 52 def worn? = worn |