Class: PackList::Item
- Inherits:
-
Object
- Object
- PackList::Item
- Defined in:
- lib/packlist/model.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #consumable? ⇒ Boolean
-
#initialize(name, description, weight, type = nil, quantity: 1) ⇒ Item
constructor
A new instance of Item.
- #total_weight ⇒ Object
- #worn? ⇒ Boolean
Constructor Details
#initialize(name, description, weight, type = nil, quantity: 1) ⇒ Item
Returns a new instance of Item.
66 67 68 69 |
# File 'lib/packlist/model.rb', line 66 def initialize(name, description, weight, type=nil, quantity: 1) @name, @description, @quantity, @type = name, description, quantity, type @weight = weight.respond_to?(:units) ? weight : Weight.new(weight, :oz) end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
64 65 66 |
# File 'lib/packlist/model.rb', line 64 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
64 65 66 |
# File 'lib/packlist/model.rb', line 64 def name @name end |
#quantity ⇒ Object
Returns the value of attribute quantity.
64 65 66 |
# File 'lib/packlist/model.rb', line 64 def quantity @quantity end |
#weight ⇒ Object
Returns the value of attribute weight.
64 65 66 |
# File 'lib/packlist/model.rb', line 64 def weight @weight end |
Instance Method Details
#consumable? ⇒ Boolean
79 80 81 |
# File 'lib/packlist/model.rb', line 79 def consumable? return @type == :consumable end |
#total_weight ⇒ Object
71 72 73 |
# File 'lib/packlist/model.rb', line 71 def total_weight return @weight * @quantity end |
#worn? ⇒ Boolean
75 76 77 |
# File 'lib/packlist/model.rb', line 75 def worn? return @type == :worn end |