File: model.rb

package info (click to toggle)
tempura 0.1.2r3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 400 kB
  • ctags: 399
  • sloc: ruby: 1,826; makefile: 84; xml: 80
file content (35 lines) | stat: -rw-r--r-- 470 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Model

  class Item
    attr_reader :name, :price
    def initialize(name,price)
      @name = name
      @price = price
    end
  end

  attr_reader :items

  def initialize
    @items = []
  end

  def amount
    val = 0
    items.each { |i| val += i.price }
    return val
  end

  def add_item(name,price)
    @items.push Item.new(name,price)
  end

  def del_item(name)
    @items.delete_if {|i| i.name == name }
  end

  def reset
    @items = []
  end

end