Class: PackList::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/packlist/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



64
65
66
# File 'lib/packlist/model.rb', line 64

def description
  @description
end

#nameObject

Returns the value of attribute name.



64
65
66
# File 'lib/packlist/model.rb', line 64

def name
  @name
end

#quantityObject

Returns the value of attribute quantity.



64
65
66
# File 'lib/packlist/model.rb', line 64

def quantity
  @quantity
end

#weightObject

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

Returns:

  • (Boolean)


79
80
81
# File 'lib/packlist/model.rb', line 79

def consumable?
  return @type == :consumable
end

#total_weightObject



71
72
73
# File 'lib/packlist/model.rb', line 71

def total_weight
  return @weight * @quantity
end

#worn?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/packlist/model.rb', line 75

def worn?
  return @type == :worn
end