Class: PackList::Category
- Inherits:
-
Object
- Object
- PackList::Category
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/packlist/model.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #base_weight ⇒ Object
- #consumable_weight ⇒ Object
-
#initialize(name, description = nil) ⇒ Category
constructor
A new instance of Category.
- #item_count ⇒ Object
- #total_pack_weight ⇒ Object
- #total_quantity ⇒ Object
- #total_weight ⇒ Object
- #worn_weight ⇒ Object
Constructor Details
#initialize(name, description = nil) ⇒ Category
Returns a new instance of Category.
93 94 95 96 |
# File 'lib/packlist/model.rb', line 93 def initialize(name, description=nil) @name, @description = name, description @items = [] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
89 90 91 |
# File 'lib/packlist/model.rb', line 89 def description @description end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
90 91 92 |
# File 'lib/packlist/model.rb', line 90 def items @items end |
#name ⇒ Object
Returns the value of attribute name.
89 90 91 |
# File 'lib/packlist/model.rb', line 89 def name @name end |
Instance Method Details
#base_weight ⇒ Object
116 117 118 119 |
# File 'lib/packlist/model.rb', line 116 def base_weight items = @items.reject {|item| item.worn? || item.consumable? } items.collect {|item| item.total_weight}.reduce(Weight::ZERO, :+) end |
#consumable_weight ⇒ Object
111 112 113 114 |
# File 'lib/packlist/model.rb', line 111 def consumable_weight items = @items.select {|item| item.consumable? } items.collect {|item| item.total_weight}.reduce(Weight::ZERO, :+) end |
#item_count ⇒ Object
125 126 127 |
# File 'lib/packlist/model.rb', line 125 def item_count @items.length end |
#total_pack_weight ⇒ Object
102 103 104 |
# File 'lib/packlist/model.rb', line 102 def total_pack_weight base_weight + consumable_weight end |
#total_quantity ⇒ Object
121 122 123 |
# File 'lib/packlist/model.rb', line 121 def total_quantity @items.collect {|item| item.quantity}.reduce(0, :+) end |