shopicruit 0.0.1 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +24 -17
- data/lib/shopicruit/version.rb +1 -1
- data/lib/shopicruit.rb +8 -8
- data/spec/shopicruit_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4983ee73be467a49610ab092a3a026a38b146bbe
|
4
|
+
data.tar.gz: 187f001d1f6c45130300e2d6476cb50d20c172b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71b0f19172d2c39442b005627008f875bfbeae60544bcc691931e51fa12377732a6ea87f419d4a69bd63714f573bf7911cff6be08044ef731a2c255acf06c918
|
7
|
+
data.tar.gz: adbcf173f0beaf6d6115bf8525904b39c3373ae229e38f9bfb86b686cb132d2631330b086db4400ef5d4ca38b885fd96e3c1d61fe39bf24bbbc52001b737833f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Shopicruit
|
2
2
|
|
3
|
-
This is a RubyGem that will calculate the maximum amount of
|
3
|
+
This is a RubyGem that will calculate the maximum amount of products that you would be able to purchase at Shopicruit store.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,28 +20,35 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
maxAmount method calculates the maximum amount of items that could be purchased within the weight limit
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
* maxAmount method calculates the maximum amount of items that could be purchased within the weight limit.\s\s
|
24
|
+
It takes three arguments:
|
25
|
+
+ First argument takes in the maximum weight in kg.
|
26
|
+
+ Second argument takes in the desired return type. ('cost', 'weight', or 'products')
|
27
|
+
+ Third arguments takes in a list of types of products. ('Keyboard', 'Computer', 'Clock', 'Car', 'Bottle', 'Wallet', 'Knife', 'Lamp', 'Table', 'Chair', 'Hat', 'Shoes', 'Plate', 'Gloves', 'Bag', 'Coat', 'Pants')
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Total cost
|
31
|
+
Shopicruit.maxAmount(100, 'cost', ['Computer' ,'Keyboard'])
|
27
32
|
|
28
|
-
|
29
|
-
|
33
|
+
# Total weight
|
34
|
+
Shopicruit.maxAmount(100, 'weight', ['Computer' ,'Keyboard'])
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
# A list of purchased items
|
37
|
+
Shopicruit.maxAmount(100, 'products', ['Computer' ,'Keyboard'])
|
38
|
+
```
|
34
39
|
|
35
|
-
leaseCost method will take into account the cost.
|
40
|
+
* leaseCost method will take into account the cost.
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
```ruby
|
43
|
+
# Total cost
|
44
|
+
Shopicruit.leaseCost(100, 'cost', ['Computer' ,'Keyboard'])
|
39
45
|
|
40
|
-
|
41
|
-
|
46
|
+
# Total weight
|
47
|
+
Shopicruit.leaseCost(100, 'weight', ['Computer' ,'Keyboard'])
|
42
48
|
|
43
|
-
|
44
|
-
|
49
|
+
# A list of purchased items
|
50
|
+
Shopicruit.leaseCost(100, 'products', ['Computer' ,'Keyboard'])
|
51
|
+
```
|
45
52
|
|
46
53
|
Happy shopping.
|
47
54
|
|
data/lib/shopicruit/version.rb
CHANGED
data/lib/shopicruit.rb
CHANGED
@@ -3,21 +3,21 @@ require 'json'
|
|
3
3
|
require 'net/http'
|
4
4
|
|
5
5
|
class Shopicruit
|
6
|
-
def self.maxAmount(maxWeight,
|
7
|
-
products = get_product_list.sort_by{ |key, value| value["weight"] }.to_h
|
6
|
+
def self.maxAmount(maxWeight, return_type, item_list)
|
7
|
+
products = get_product_list(item_list).sort_by{ |key, value| value["weight"] }.to_h
|
8
8
|
result = calculate(products, maxWeight)
|
9
|
-
return result[
|
9
|
+
return result[return_type]
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
|
-
def self.leastCost(maxWeight,
|
14
|
-
products = get_product_list.sort_by{ |key, value| value["price"] / value["weight"] }.to_h
|
13
|
+
def self.leastCost(maxWeight, return_type, item_list)
|
14
|
+
products = get_product_list(item_list).sort_by{ |key, value| value["price"] / value["weight"] }.to_h
|
15
15
|
result = calculate(products, maxWeight)
|
16
|
-
return result[
|
16
|
+
return result[return_type]
|
17
17
|
end
|
18
18
|
|
19
19
|
|
20
|
-
def self.get_product_list
|
20
|
+
def self.get_product_list(item_list)
|
21
21
|
uri = URI("http://shopicruit.myshopify.com/products.json")
|
22
22
|
|
23
23
|
res = Net::HTTP.get(uri)
|
@@ -25,7 +25,7 @@ class Shopicruit
|
|
25
25
|
|
26
26
|
desiredProductList = {}
|
27
27
|
product_list["products"].each do |item|
|
28
|
-
if (
|
28
|
+
if (item_list.include? item["product_type"])
|
29
29
|
item["variants"].each do |var|
|
30
30
|
title = item["title"] + " (" + var["title"] + ")"
|
31
31
|
desiredProductList[title] = { "weight" => var["grams"], "price" => var["price"].to_f }
|
data/spec/shopicruit_spec.rb
CHANGED
@@ -7,17 +7,17 @@ describe Shopicruit do
|
|
7
7
|
let(:input) { 100 }
|
8
8
|
|
9
9
|
it 'tests that the cost of leastCost method is smaller than that of maxAmount' do
|
10
|
-
expect( Shopicruit.maxAmount(input, 'cost')[1..-1].to_i ).to be >= ( Shopicruit.
|
10
|
+
expect( Shopicruit.maxAmount(input, 'cost', ['Computer', 'Keyboard'])[1..-1].to_i ).to be >= ( Shopicruit.leastCost(input, 'cost', ['Computer', 'Keyboard'])[1..-1].to_i )
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'tests that purchased weight does not exceed limit' do
|
14
|
-
expect( Shopicruit.maxAmount(input, 'weight')[0..-3].to_i ).to be <= input
|
15
|
-
expect( Shopicruit.leastCost(input, 'weight')[0..-3].to_i ).to be <= input
|
14
|
+
expect( Shopicruit.maxAmount(input, 'weight', ['Computer', 'Keyboard'])[0..-3].to_i ).to be <= input
|
15
|
+
expect( Shopicruit.leastCost(input, 'weight', ['Computer', 'Keyboard'])[0..-3].to_i ).to be <= input
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'tests that the purchased products are valid' do
|
19
|
-
expect( Shopicruit.maxAmount(input, 'products').length ).to be > 0
|
20
|
-
expect( Shopicruit.leastCost(input, 'products').length ).to be > 0
|
19
|
+
expect( Shopicruit.maxAmount(input, 'products', ['Computer', 'Keyboard']).length ).to be > 0
|
20
|
+
expect( Shopicruit.leastCost(input, 'products', ['Computer', 'Keyboard']).length ).to be > 0
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|