rafa-product-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/price_record.rb +24 -0
- data/lib/till.rb +23 -0
- metadata +62 -0
data/lib/price_record.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
module PriceRecord
|
3
|
+
class << self
|
4
|
+
def initialize
|
5
|
+
@price_list = {}
|
6
|
+
|
7
|
+
price_list_string = "orange = £30 apple = 20p bread = £50 tomato = 25p cereal = £20"
|
8
|
+
price_list_string.scan(/(\w+)\s=\s[£]*([\d,\.]*)/).each do |match|
|
9
|
+
@price_list[match[0]] = price_in_pence(match[1])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def getPrice name
|
14
|
+
PriceRecord.initialize unless @price_list
|
15
|
+
@price_list[name]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def price_in_pence string
|
20
|
+
string.include?('.') ? (string.to_f * 100).to_i : string.to_i
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/till.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
require "price_record"
|
3
|
+
|
4
|
+
class Till
|
5
|
+
attr_reader :total
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@total = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def add names
|
12
|
+
#product = Struct.new(:name, :price) do
|
13
|
+
# def to_s
|
14
|
+
# p " Item name: #{@name}.Item price: #{@price}"
|
15
|
+
# end
|
16
|
+
#end
|
17
|
+
names.each do |name|
|
18
|
+
#@prods||=[] << product.new(name, PriceRecord.getPrice(name))
|
19
|
+
@total += PriceRecord.getPrice(name)
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rafa-product-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- rafa
|
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'
|
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'
|
30
|
+
description: Much longer explanation of the example!
|
31
|
+
email: rafayandrey89@yahoo.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/till.rb
|
37
|
+
- lib/price_record.rb
|
38
|
+
homepage: https://rubygems.org/gems/rafa-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: This is an example!
|
62
|
+
test_files: []
|