mobistore 0.0.2 → 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: 7910c1b62b6055f9b0b95e18ba9ff2ee7a3cff8b
4
- data.tar.gz: 2aba8f49c9fb69ab64faa98d08505483337e693f
3
+ metadata.gz: b465d209c6ce528a0a32a542d4d3dfd3630d8d6c
4
+ data.tar.gz: f4aaec8bb595c8a4374a32c3a055a3aeb34845f3
5
5
  SHA512:
6
- metadata.gz: deaf8b2ed0d4fcdffd6e2daf846b7abfc0928a35ae136320db82e541a5dc8c95d6a83e5ea7a80c0636b9559157d8072dcf84805f7bf28e52e63a05527774254e
7
- data.tar.gz: 248a364d4265da3b9223bbd289b1903a9cad80092ee2bf861e53097f4ed978363dbccea7b3e6afa0e64f0de3f909b00a97f1d7c58a223896d0b4a9dfd0442dc3
6
+ metadata.gz: 3f7e0952193ab156de4f4ff3584a9835e3421be93398635231d93fb1a572416a4a4fcbfde3eb8c101fca39c79d1c27b5aff6d0739da5c7b5d42f397db5e45f1d
7
+ data.tar.gz: d636ccedd9fc4cbe1f0864bda7935a225b888722fc06cf94ec351b3093be6359137d8912fe8da2b4d254529654b033b3abc7008f99308c94c05ae54c9cf506c0
@@ -4,12 +4,15 @@ class BuyerAPI
4
4
 
5
5
  extend UserModule
6
6
 
7
+ $BUYER_OPTIONS = { list: "list", search: "search", buy: "buy"}
8
+
7
9
  @@name = "Raj Negi"
8
10
  @@money = 5000
9
11
  @@cc_details = "icic"
10
12
 
13
+
11
14
  def self.buy
12
- puts "\tEnter the details of product you want to buy: "
15
+ puts "\n\tEnter the details of product you want to buy ('q' to quit): "
13
16
  product_id = get_number("ID")
14
17
  product = ProductAPI.search_id(product_id)
15
18
 
@@ -1,7 +1,7 @@
1
1
  {"name":"LG 5","color":"grey","price":300,"quantity":4,"id":0}
2
- {"name":"Samsung Galaxy Note","color":"galaxy white","price":324,"quantity":11,"id":1}
3
- {"name":"Apple iPhone 7","color":"space black","price":600,"quantity":2,"id":2}
4
- {"name":"OnePlus 3","color":"wooden","price":601,"quantity":0,"id":3}
2
+ {"name":"Samsung Galaxy Note","color":"galaxy white","price":324,"quantity":10,"id":1}
3
+ {"name":"Apple iPhone 7","color":"space black","price":600,"quantity":1,"id":2}
4
+ {"name":"OnePlus 3","color":"wooden","price":601,"quantity":20,"id":3}
5
5
  {"del":true}
6
6
  {"name":"Oppo Smartphone","color":"matte","price":250,"quantity":2,"id":5}
7
7
  {"del":true}
@@ -5,3 +5,5 @@
5
5
  {"product_name":"Samsung Galaxy Note","buyer_name":"raj","buyer_cc_details":"icic","timestamp":"2016-09-16 15:44:41 +0530","amount_paid":324,"id":4}
6
6
  {"product_name":"LG 5","buyer_name":"raj","buyer_cc_details":"icic","timestamp":"2016-09-16 15:46:42 +0530","amount_paid":300,"id":5}
7
7
  {"product_name":"Oppo Smartphone","buyer_name":"Raj Negi","buyer_cc_details":"icic","timestamp":"2016-09-16 16:11:04 +0530","amount_paid":250,"id":6}
8
+ {"product_name":"Samsung Galaxy Note","buyer_name":"Raj Negi","buyer_cc_details":"icic","timestamp":"2016-09-20 18:22:41 +0530","amount_paid":324,"id":7}
9
+ {"product_name":"Apple iPhone 7","buyer_name":"Raj Negi","buyer_cc_details":"icic","timestamp":"2016-09-20 18:45:15 +0530","amount_paid":600,"id":8}
@@ -4,10 +4,10 @@ class ProductAPI
4
4
 
5
5
  extend FileStorageModule
6
6
 
7
+
7
8
  @@file_path = File.join(File.dirname(caller[0]), "/FileStorage/products.log")
8
9
 
9
10
  def self.seed
10
- byebug
11
11
  @@list = read_file(@@file_path)
12
12
  end
13
13
 
@@ -1,5 +1,8 @@
1
1
  require_relative 'UserModule.rb'
2
2
 
3
+ $SELLER_OPTIONS = {list: "list", search: "search", add: "add", update: "update", delete: "delete"}
4
+ $PRODUCT_FIELD = {name: "Name", color: "Price", quantity: "Quantity"}
5
+
3
6
  class SellerAPI
4
7
 
5
8
  attr_accessor :id, :name, :money, :valid_hash
@@ -7,30 +10,40 @@ class SellerAPI
7
10
  extend UserModule
8
11
 
9
12
  def self.add_product
10
- puts "Enter product details:"
13
+ puts "Enter product details: ('q' to quit )"
14
+
15
+ name = get_string($PRODUCT_FIELD[:name])
16
+ return if name == -1
17
+ color = get_string($PRODUCT_FIELD[:color])
18
+ return if color == -1
19
+ price = get_number($PRODUCT_FIELD[:price])
20
+ return if price == -1
21
+ quantity = get_number($PRODUCT_FIELD[:quantity])
22
+ return if quantity == -1
11
23
 
12
- name = get_string("Name")
13
- color = get_string("Color")
14
- price = get_number("Price")
15
- quantity = get_number("Quantity")
16
24
  product = {name: name, color: color, price: price, quantity: quantity}
17
25
  ProductAPI.add(product)
18
26
  end
19
27
 
20
28
  def self.update_product
21
29
  list_products
22
- puts "\n\tEnter the product needed to be updated: "
30
+ puts "\n\tEnter the product needed to be updated: ('q' to quit) "
23
31
 
24
32
  id = get_number("ID of product")
33
+ return if id == -1
25
34
  key = get_string("Update field ")
35
+ return if key == -1
26
36
  value = get_string("New value for '#{key}'")
37
+ return if id == -1
38
+
27
39
  ProductAPI.update(id, key.to_sym, value)
28
40
  end
29
41
 
30
42
  def self.delete_product
31
43
  list_products
32
- print "\n\tEnter product id to be deleted: "
44
+ print "\n\tEnter product id to be deleted ('q' to quit): "
33
45
  id = gets.chomp.to_i
46
+ return if id == -1
34
47
  ProductAPI.delete(id)
35
48
  end
36
49
 
@@ -10,15 +10,19 @@ module UserModule
10
10
  list_products
11
11
  print "\n"
12
12
  key = get_string("product by? 'name' | 'id' | 'color' ")
13
+ return if key == -1
13
14
  value = get_string("search value for '#{key}' ")
15
+ return if value == -1
14
16
  puts ProductAPI.search(key.to_sym, value)
15
17
  end
16
18
 
17
19
  def get_number(label)
18
20
  print "\tEnter #{label}: "
19
21
  value = gets.chomp
20
- if !!(value =~ /[0-9]/)
22
+ if !!(value =~ /[0-9]+/ && value.length == value.match(/[0-9]+/).to_s.length )
21
23
  return value.to_i
24
+ elsif value == 'q'
25
+ return -1
22
26
  else
23
27
  puts "\tInvalid #{label} value. Try again."
24
28
  return self.get_number(label)
@@ -28,8 +32,10 @@ module UserModule
28
32
  def get_string(label)
29
33
  print "\tEnter #{label}: "
30
34
  value = gets.chomp
31
- unless value.strip.empty?
35
+ if !(value.strip.empty?)
32
36
  return value
37
+ elsif value == 'q'
38
+ return -1
33
39
  else
34
40
  puts "\tInvalid #{label} value. Try again."
35
41
  return self.get_string(label)
@@ -6,28 +6,35 @@ require_relative 'SellerAPI.rb'
6
6
  class MobiStore
7
7
 
8
8
  def self.get_logo
9
- "\n\t\t\t________________\n"+
10
- "\t\t\t[The Mobi Store]"+
11
- "\n\n\n"
9
+ "\n\t\t\t________________\n" +
10
+ "\t\t\t[The Mobi Store]" +
11
+ "\n\n\n"
12
12
  end
13
13
 
14
14
  def self.show_seller_options
15
15
  system 'clear'
16
16
  loop do
17
- print "#{get_logo}\tEnter your option:\n\t'list' | 'search' | 'add' | 'update' | 'delete' | 'quit' : "
17
+ print "#{get_logo}\tEnter your option:\n\t " +
18
+ "'#{$SELLER_OPTIONS[:list]}' | " +
19
+ "'#{$SELLER_OPTIONS[:search]}'| " +
20
+ "'#{$SELLER_OPTIONS[:add]}' | " +
21
+ "'#{$SELLER_OPTIONS[:update]}'| " +
22
+ "'#{$SELLER_OPTIONS[:update]}'| " +
23
+ "'quit' (q) : "
24
+
18
25
  choice = gets.chomp.downcase
19
26
 
20
- if choice == "list"
27
+ if choice == $SELLER_OPTIONS[:list]
21
28
  SellerAPI.list_products
22
- elsif choice == "search"
29
+ elsif choice == $SELLER_OPTIONS[:search]
23
30
  SellerAPI.search_product
24
- elsif choice == "add"
31
+ elsif choice == $SELLER_OPTIONS[:add]
25
32
  SellerAPI.add_product
26
- elsif choice == 'update'
33
+ elsif choice == $SELLER_OPTIONS[:update]
27
34
  SellerAPI.update_product
28
- elsif choice == 'delete'
35
+ elsif choice == $SELLER_OPTIONS[:delete]
29
36
  SellerAPI.delete_product
30
- elsif choice == "quit"
37
+ elsif choice == "quit" || choice == 'q'
31
38
  break
32
39
  else
33
40
  puts "Woops, invalid input. Can you enter again?"
@@ -39,16 +46,21 @@ class MobiStore
39
46
  def self.show_buyer_options
40
47
  system 'clear'
41
48
  loop do
42
- print "#{get_logo}\tEnter your option:\n\t'list' | 'search' | 'buy' | 'quit' : "
49
+ print "#{get_logo}\tEnter your option:\n\t " +
50
+ "'#{$BUYER_OPTIONS[:list]}' | " +
51
+ "'#{$BUYER_OPTIONS[:search]}'| " +
52
+ "'#{$BUYER_OPTIONS[:buy]}' | " +
53
+ "'quit' (q) : "
43
54
  choice = gets.chomp.downcase
44
55
 
45
- if choice == "list"
56
+ if choice == $BUYER_OPTIONS[:list]
46
57
  BuyerAPI.list_products
47
- elsif choice == "search"
58
+ elsif choice == $BUYER_OPTIONS[:search]
48
59
  BuyerAPI.search_product
49
- elsif choice == "buy"
60
+ elsif choice == $BUYER_OPTIONS[:buy]
61
+ BuyerAPI.list_products
50
62
  BuyerAPI.buy
51
- elsif choice == "quit"
63
+ elsif choice == "quit" || choice == 'q'
52
64
  break
53
65
  else
54
66
  puts "Woops, invalid input. Can you enter again?"
@@ -62,12 +74,14 @@ class MobiStore
62
74
  ProductAPI.seed
63
75
  TranscationAPI.seed
64
76
  system 'clear'
65
- print "#{get_logo}\tWhich type of user are you? 'Buyer' | 'Seller' : "
77
+ print "#{get_logo}\tWhich type of user are you? 'Buyer'(b) | 'Seller'(s) | 'quit'(q) : "
66
78
  choice = gets.chomp.downcase
67
- if choice == "buyer"
79
+ if choice == "buyer" || choice == "b"
68
80
  show_buyer_options
69
- elsif choice == "seller"
81
+ elsif choice == "seller" || choice == "s"
70
82
  show_seller_options
83
+ elsif choice == "quit" || choice == "q"
84
+ return
71
85
  else
72
86
  puts "Invalid input, try again?"
73
87
  return init
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobistore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raj Negi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-16 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Mobile store, with built-in JSON database and seeded objects. Type 'MobiStore.init'
14
14
  to get started