Class: PackList::Category

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/packlist/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



89
90
91
# File 'lib/packlist/model.rb', line 89

def description
  @description
end

#itemsObject (readonly)

Returns the value of attribute items.



90
91
92
# File 'lib/packlist/model.rb', line 90

def items
  @items
end

#nameObject

Returns the value of attribute name.



89
90
91
# File 'lib/packlist/model.rb', line 89

def name
  @name
end

Instance Method Details

#base_weightObject



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_weightObject



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_countObject



125
126
127
# File 'lib/packlist/model.rb', line 125

def item_count
  @items.length
end

#total_pack_weightObject



102
103
104
# File 'lib/packlist/model.rb', line 102

def total_pack_weight
  base_weight + consumable_weight
end

#total_quantityObject



121
122
123
# File 'lib/packlist/model.rb', line 121

def total_quantity
  @items.collect {|item| item.quantity}.reduce(0, :+)
end

#total_weightObject



98
99
100
# File 'lib/packlist/model.rb', line 98

def total_weight
  @items.collect {|item| item.total_weight}.reduce(Weight::ZERO, :+)
end

#worn_weightObject



106
107
108
109
# File 'lib/packlist/model.rb', line 106

def worn_weight
  items = @items.select {|item| item.worn? }
  items.collect {|item| item.total_weight}.reduce(Weight::ZERO, :+)
end