unit4-checkout 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20fb37514a5fb308e875ce79947dcd5b4ab4adc20aeb99b4c96b6160b35ecaf1
4
- data.tar.gz: d087f7c297fd98cc3134f5c3a73561ade3b8a83c2f54b06e93a7d6116ace5af3
3
+ metadata.gz: 83982e7ddae1c09934ca1125ae9cfb0b0b8b845638fbce0eb19472137057652b
4
+ data.tar.gz: fb8982c906834e642dcaedbd81cdb89f258555c1dcbab7f73dc1387a9cd609fa
5
5
  SHA512:
6
- metadata.gz: 2115c82a2d30e48c3881cc956d1920bcf55d07619198db6fc7b89baccc8245bc65e0ae534b885da3c159a55e1880e23791cba0531ac55bd8430388165c453d98
7
- data.tar.gz: 1bcbb461a144d71b67e3d7d63bb1493a4dd4f5026ed2caafab11b3758f595a89e2a66f809dab81c663a0b4378f232402662b583b282e95eac813ce3df7fed280
6
+ metadata.gz: 514d5a25a55f090eb87ebcd5d49ce013b7638efa885e79dd59270c361bcb0462f929140706413d04624a5bfdfdad757f07648dc8403f188d72b07fe36b48bee3
7
+ data.tar.gz: 1721ec7136a1c447903ffbfdbad3ce2c7d0fea7ff11c19eed5ca57a5adfcdd3895b16d930d3a34a910dfd2a21ccf5dc08cf7d200f2945872ceb80502fa74b4da
data/Gemfile CHANGED
@@ -10,3 +10,7 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem "activerecord"
15
+
16
+ gem "erb"
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unit4-checkout (0.1.2)
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,7 @@
1
+ class Basket
2
+ attr_accessor :items
3
+
4
+ def initialize
5
+ @items = {}
6
+ end
7
+ end
@@ -0,0 +1,74 @@
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, :result
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
+ find_item_price(item)
31
+ item_price = 3
32
+ new_discount_available?(item) ? apply_discounts : @total += item_price
33
+ @total
34
+ end
35
+
36
+ def find_item_price(item)
37
+ query = "SELECT * FROM 'users' WHERE 'users'.'id' = ?"
38
+ sanitized_query = ActiveRecord::Base.sanitize_sql_array([query, item])
39
+ execute_statement(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
+ @result = 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
+ defined?(Rails) && defined?(Rails.env) ? rails_db_config : non_rails_db_config
58
+ end
59
+
60
+ def rails_db_config
61
+ Rails.application.config.database_configuration[Rails.env]
62
+ end
63
+
64
+ def non_rails_db_config
65
+ # TODO: use current database instead of development
66
+ YAML.safe_load(ERB.new(File.read("./config/database.yml")).result, aliases: true)["development"]
67
+ end
68
+
69
+ # maybe add remove item function
70
+
71
+ def add_to_basket(item)
72
+ @basket.items[item] ? @basket.items[item] += 1 : @basket.items[item] = 1
73
+ end
74
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unit4
4
4
  module Checkout
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "checkout/version"
4
+ require_relative "checkout/checkout"
5
+ require_relative "checkout/basket"
4
6
 
5
7
  module Unit4
6
8
  module Checkout
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.0
4
+ version: 0.1.3
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-20 00:00:00.000000000 Z
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