unit4-checkout 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/Gemfile.lock +76 -0
- data/lib/unit4/checkout/basket.rb +7 -0
- data/lib/unit4/checkout/checkout.rb +70 -0
- data/lib/unit4/checkout/version.rb +1 -1
- data/lib/unit4/checkout.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25e056e024c30930dc8e8dcd397bee9feb0abd6bcdb2a28c964d7c9328a64e0f
|
4
|
+
data.tar.gz: 72ed5b82d6d72c2506794a561980fb1bc1885839c21f29e5f03dbd92f5003e3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 348646bf3be47c132984c6f21d12375321e1d30846ab5b1bf7194063629721a86db078199fc21762ab6294e9ef310ef851156c75e584baf78e6f750e895a27bc
|
7
|
+
data.tar.gz: cceaee303633c791c525b05cfd769a4f38ffc56085c1f5af3101ea73eacae5d26746285060172eb818676a6c78fb7a262d0ca6fc518dfcdd52d65d8e37fb5696
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
unit4-checkout (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (7.0.3.1)
|
10
|
+
activesupport (= 7.0.3.1)
|
11
|
+
activerecord (7.0.3.1)
|
12
|
+
activemodel (= 7.0.3.1)
|
13
|
+
activesupport (= 7.0.3.1)
|
14
|
+
activesupport (7.0.3.1)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
tzinfo (~> 2.0)
|
19
|
+
ast (2.4.2)
|
20
|
+
cgi (0.3.2)
|
21
|
+
concurrent-ruby (1.1.10)
|
22
|
+
diff-lcs (1.5.0)
|
23
|
+
erb (2.2.3)
|
24
|
+
cgi
|
25
|
+
i18n (1.12.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
minitest (5.16.2)
|
28
|
+
parallel (1.21.0)
|
29
|
+
parser (3.1.0.0)
|
30
|
+
ast (~> 2.4.1)
|
31
|
+
rainbow (3.1.1)
|
32
|
+
rake (13.0.6)
|
33
|
+
regexp_parser (2.5.0)
|
34
|
+
rexml (3.2.5)
|
35
|
+
rspec (3.11.0)
|
36
|
+
rspec-core (~> 3.11.0)
|
37
|
+
rspec-expectations (~> 3.11.0)
|
38
|
+
rspec-mocks (~> 3.11.0)
|
39
|
+
rspec-core (3.11.0)
|
40
|
+
rspec-support (~> 3.11.0)
|
41
|
+
rspec-expectations (3.11.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.11.0)
|
44
|
+
rspec-mocks (3.11.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.11.0)
|
47
|
+
rspec-support (3.11.0)
|
48
|
+
rubocop (1.25.1)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 3.1.0.0)
|
51
|
+
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
regexp_parser (>= 1.8, < 3.0)
|
53
|
+
rexml
|
54
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
55
|
+
ruby-progressbar (~> 1.7)
|
56
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.15.2)
|
58
|
+
parser (>= 3.0.1.1)
|
59
|
+
ruby-progressbar (1.11.0)
|
60
|
+
tzinfo (2.0.5)
|
61
|
+
concurrent-ruby (~> 1.0)
|
62
|
+
unicode-display_width (2.1.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
x86_64-linux
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
activerecord
|
69
|
+
erb
|
70
|
+
rake (~> 13.0)
|
71
|
+
rspec (~> 3.0)
|
72
|
+
rubocop (~> 1.21)
|
73
|
+
unit4-checkout!
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
2.3.15
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
require "erb"
|
5
|
+
|
6
|
+
class Checkout
|
7
|
+
attr_reader :promotional_rules, :total, :basket, :price_discount_applied_flag
|
8
|
+
|
9
|
+
# {product_discounts: {001: {count:2, price: 3.25}, 004: {count:2, price: 3.25}}, total_price_discount: $50}
|
10
|
+
def initialize(promotional_rules)
|
11
|
+
# maybe raise another error if keys aren't ids or total price, possibly total_item_count
|
12
|
+
raise TypeError, "expected a Hash, got #{promotional_rules.class.name}" unless promotional_rules.is_a? Hash
|
13
|
+
|
14
|
+
@promotional_rules = promotional_rules
|
15
|
+
@total = 0
|
16
|
+
@basket = Basket.new
|
17
|
+
establish_connection
|
18
|
+
end
|
19
|
+
|
20
|
+
# maybe facilitate scanning multiple items at once
|
21
|
+
# no structure for item given, assumed id
|
22
|
+
def scan(item)
|
23
|
+
# check for item id
|
24
|
+
add_to_basket(item)
|
25
|
+
calculate_total(item)
|
26
|
+
puts "#{item.capitalize} has been added to the basket successfully!"
|
27
|
+
end
|
28
|
+
|
29
|
+
def calculate_total(item)
|
30
|
+
item_price = find_item_price(item)
|
31
|
+
new_discount_available?(item) ? apply_discounts : @total += item_price
|
32
|
+
@total
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_item_price(item)
|
36
|
+
query = "SELECT * FROM 'users' WHERE 'users'.'id' = ?"
|
37
|
+
sanitized_query = ActiveRecord::Base.sanitize_sql_array([query, item])
|
38
|
+
execute_statement(sanitized_query)
|
39
|
+
ActiveRecord::Base.connection.exec_query(sanitized_query)
|
40
|
+
end
|
41
|
+
|
42
|
+
def apply_discounts; end
|
43
|
+
|
44
|
+
def new_discount_available?(item); end
|
45
|
+
|
46
|
+
def execute_statement(sql)
|
47
|
+
results = ActiveRecord::Base.connection.exec_query(sql)
|
48
|
+
results if results.present?
|
49
|
+
end
|
50
|
+
|
51
|
+
def establish_connection
|
52
|
+
db_config = setup_db_config
|
53
|
+
ActiveRecord::Base.establish_connection(adapter: db_config["adapter"], database: db_config["database"])
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_db_config
|
57
|
+
if defined? Rails && defined? Rails.env
|
58
|
+
Rails.application.config.database_configuration[Rails.env]
|
59
|
+
else
|
60
|
+
# TODO: use current database instead of development
|
61
|
+
YAML.safe_load(ERB.new(File.read("./config/database.yml")).result, aliases: true)["development"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# maybe add remove item function
|
66
|
+
|
67
|
+
def add_to_basket(item)
|
68
|
+
@basket[item] ? @basket["item"] += 1 : @basket["item"] = 1
|
69
|
+
end
|
70
|
+
end
|
data/lib/unit4/checkout.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unit4-checkout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boyan Georgiev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Initial commit
|
14
14
|
email:
|
@@ -20,9 +20,12 @@ files:
|
|
20
20
|
- ".rspec"
|
21
21
|
- ".rubocop.yml"
|
22
22
|
- Gemfile
|
23
|
+
- Gemfile.lock
|
23
24
|
- README.md
|
24
25
|
- Rakefile
|
25
26
|
- lib/unit4/checkout.rb
|
27
|
+
- lib/unit4/checkout/basket.rb
|
28
|
+
- lib/unit4/checkout/checkout.rb
|
26
29
|
- lib/unit4/checkout/version.rb
|
27
30
|
- sig/unit4/checkout.rbs
|
28
31
|
homepage: https://github.com/BoyanGeorgiev96/unit4-checkout
|