Cypy46-produce_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Lib/basket.rb +33 -0
- data/Lib/till.rb +18 -0
- metadata +62 -0
data/Lib/basket.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Basket
|
2
|
+
attr_reader :total
|
3
|
+
|
4
|
+
def initialize values
|
5
|
+
@total = 0
|
6
|
+
@products = values
|
7
|
+
@price_map = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def add product, price
|
11
|
+
if @products.include? product
|
12
|
+
update_by product, price
|
13
|
+
elsif @products.empty?
|
14
|
+
raise Exception, "No products registered"
|
15
|
+
else
|
16
|
+
raise Exception, "No such product registered: #{product}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
=begin
|
21
|
+
def print
|
22
|
+
@price_map.each_pair { |k, v| puts k + " = " +v }
|
23
|
+
end
|
24
|
+
=end
|
25
|
+
|
26
|
+
private
|
27
|
+
def update_by product, price
|
28
|
+
current_price = @price_map[product].to_i
|
29
|
+
current_price += price.to_i
|
30
|
+
@price_map[product] = current_price.to_s
|
31
|
+
@total += price.to_i
|
32
|
+
end
|
33
|
+
end
|
data/Lib/till.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Till
|
2
|
+
def initialize prices
|
3
|
+
@prices = prices
|
4
|
+
end
|
5
|
+
|
6
|
+
def total_for basket
|
7
|
+
total = 0
|
8
|
+
basket.items.each do |item|
|
9
|
+
total = total + price_for(item)
|
10
|
+
end
|
11
|
+
return total
|
12
|
+
end
|
13
|
+
|
14
|
+
def price_for product
|
15
|
+
@prices[product]
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Cypy46-produce_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cypy46
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.14.1
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.14.1
|
30
|
+
description: Much longer explanation of the example!
|
31
|
+
email: Cypy46@yahoo.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- Lib/basket.rb
|
37
|
+
- Lib/till.rb
|
38
|
+
homepage: https://rubygems.org/gems/Cypy46-product_api
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.25
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Exemplu magazin'
|
62
|
+
test_files: []
|