Class: PackwizardParser::Item
- Inherits:
-
Object
- Object
- PackwizardParser::Item
- Defined in:
- lib/packwizard_parser/item.rb
Overview
Represents a single item in a PackWizard list
Instance Attribute Summary collapse
-
#consumable ⇒ Boolean
(also: #consumable?)
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.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#quantity ⇒ Integer
readonly
Number of items.
-
#total_consumable_weight ⇒ Float?
readonly
Total consumable weight (weight * quantity) if consumable, nil otherwise.
-
#total_price ⇒ Object
readonly
Returns the value of attribute total_price.
-
#total_weight ⇒ Float
readonly
Total weight (weight * quantity) in grams.
-
#total_worn_weight ⇒ Float
readonly
Total worn weight (weight * 1) if worn, 0.0 otherwise.
-
#weight ⇒ Float
readonly
Weight per item in grams.
-
#worn ⇒ Boolean
(also: #worn?)
readonly
Whether the item is worn.
-
#worn_quantity ⇒ Integer
readonly
Number of worn items (always 1 if worn, 0 otherwise).
Instance Method Summary collapse
-
#initialize(name:, weight:, total_weight:, quantity:, description: nil, image_url: nil, consumable: false, total_consumable_weight: nil, worn: false, worn_quantity:, total_worn_weight:) ⇒ Item
constructor
A new instance of Item.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize(name:, weight:, total_weight:, quantity:, description: nil, image_url: nil, consumable: false, total_consumable_weight: nil, worn: false, worn_quantity:, total_worn_weight:) ⇒ Item
Returns a new instance of Item.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/packwizard_parser/item.rb', line 32 def initialize(name:, weight:, total_weight:, quantity:, description: nil, image_url: nil, consumable: false, total_consumable_weight: nil, worn: false, worn_quantity:, total_worn_weight:) @name = name @weight = weight @description = description @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) Also known as: consumable?
Whether the item is consumable
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def consumable @consumable end |
#description ⇒ String? (readonly)
Optional description of the item
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def description @description end |
#image_url ⇒ String? (readonly)
Optional URL to item image
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def image_url @image_url end |
#name ⇒ String (readonly)
The name of the item
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def name @name end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
19 20 21 |
# File 'lib/packwizard_parser/item.rb', line 19 def price @price end |
#quantity ⇒ Integer (readonly)
Number of items
18 19 20 |
# File 'lib/packwizard_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/packwizard_parser/item.rb', line 18 def total_consumable_weight @total_consumable_weight end |
#total_price ⇒ Object (readonly)
Returns the value of attribute total_price.
19 20 21 |
# File 'lib/packwizard_parser/item.rb', line 19 def total_price @total_price end |
#total_weight ⇒ Float (readonly)
Total weight (weight * quantity) in grams
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def total_weight @total_weight end |
#total_worn_weight ⇒ Float (readonly)
Total worn weight (weight * 1) if worn, 0.0 otherwise
18 19 20 |
# File 'lib/packwizard_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/packwizard_parser/item.rb', line 18 def weight @weight end |
#worn ⇒ Boolean (readonly) Also known as: worn?
Whether the item is worn
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def worn @worn end |
#worn_quantity ⇒ Integer (readonly)
Number of worn items (always 1 if worn, 0 otherwise)
18 19 20 |
# File 'lib/packwizard_parser/item.rb', line 18 def worn_quantity @worn_quantity end |
Instance Method Details
#to_h ⇒ Hash
Convert to hash
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/packwizard_parser/item.rb', line 55 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 |