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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a374e24e5bccf2488a2dc17e1bc18f018a5a201a
4
- data.tar.gz: d502615502854a647b828a17881ed78656f62d5a
3
+ metadata.gz: 4983ee73be467a49610ab092a3a026a38b146bbe
4
+ data.tar.gz: 187f001d1f6c45130300e2d6476cb50d20c172b0
5
5
  SHA512:
6
- metadata.gz: ad168c0afed0358ff34873a0944ac1b02c6de808e22d33193dff01ac4dffb21655ce4a62200defdf849cbc367da7829ab2204d68ad19523b6bf61bbffdbe9362
7
- data.tar.gz: a48411a4461f61dbc4c1dc29d6d8982d45776be025e1901e4a551f1b59219db96ac925438b557e72e1adca94564064cde2efc13be042c3ade1392bb1526ddfce
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 computers and keyboards that you would be able to purchase at Shopicruit store.
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
- # Total cost
26
- Shopicruit.maxAmount(100, 'cost')
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
- # Total weight
29
- Shopicruit.maxAmount(100, 'weight')
33
+ # Total weight
34
+ Shopicruit.maxAmount(100, 'weight', ['Computer' ,'Keyboard'])
30
35
 
31
- # A list of purchased items
32
- Shopicruit.maxAmount(100, 'products')
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
- # Total cost
38
- Shopicruit.leaseCost(100, 'cost')
42
+ ```ruby
43
+ # Total cost
44
+ Shopicruit.leaseCost(100, 'cost', ['Computer' ,'Keyboard'])
39
45
 
40
- # Total weight
41
- Shopicruit.leaseCost(100, 'weight')
46
+ # Total weight
47
+ Shopicruit.leaseCost(100, 'weight', ['Computer' ,'Keyboard'])
42
48
 
43
- # A list of purchased items
44
- Shopicruit.leaseCost(100, 'products')
49
+ # A list of purchased items
50
+ Shopicruit.leaseCost(100, 'products', ['Computer' ,'Keyboard'])
51
+ ```
45
52
 
46
53
  Happy shopping.
47
54
 
@@ -1,3 +1,3 @@
1
1
  class Shopicruit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
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, type)
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[type]
9
+ return result[return_type]
10
10
  end
11
11
 
12
12
 
13
- def self.leastCost(maxWeight, type)
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[type]
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 (item["product_type"] == "Computer" or item["product_type"] == 'Keyboard')
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 }
@@ -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.maxAmount(input, 'cost')[1..-1].to_i )
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopicruit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lisa Weng