shopgem 0.0.1 → 0.0.2
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/lib/shopgem.rb +4 -3
- data/lib/shopgem/booksdb.rb +77 -33
- 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: c96cf4679e275d6d840c73d36bf09a5c5fe5a344
|
|
4
|
+
data.tar.gz: 526f40b50ab4111dddc6334cf0dfb7af14cdb6ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 918b205ec1ef1cbb63bd1cb4bb1a0fc0f0f08eed3bd2b6f9637830cdab6b6a732fba76c5372b3fe256cbe3f89cc0f8a37c5e46d3da61e0e233bbcfffad634419
|
|
7
|
+
data.tar.gz: e1ea862881b4eff912db425b1438190771f29cbd445d38544961a12a1c1cb6a6c608ee0d05a7e33d03e699b7488e7b591ee4e9ae854fe179efcae429e45b4178
|
data/lib/shopgem.rb
CHANGED
|
@@ -4,12 +4,12 @@ class Shopgem
|
|
|
4
4
|
obj = BookDb.new
|
|
5
5
|
|
|
6
6
|
while(0)
|
|
7
|
-
puts "\n\n************* WelCome to
|
|
7
|
+
puts "\n\n************* WelCome to BookShop *************\nSelect Operation from below"
|
|
8
8
|
puts " 1. Enter New Book in Database"
|
|
9
9
|
puts " 2. Show All Books "
|
|
10
10
|
puts " 3. Update Book"
|
|
11
11
|
puts " 4. Delete Book"
|
|
12
|
-
puts "
|
|
12
|
+
puts " 5. Add book to kart"
|
|
13
13
|
puts " 6. Show Kart"
|
|
14
14
|
puts " 7. Remove book from kart"
|
|
15
15
|
puts " 8. Checkout"
|
|
@@ -43,9 +43,10 @@ class Shopgem
|
|
|
43
43
|
when 8
|
|
44
44
|
puts 'Checkout'
|
|
45
45
|
obj.checkout
|
|
46
|
-
when 9
|
|
46
|
+
when 9
|
|
47
47
|
break;
|
|
48
48
|
else
|
|
49
|
+
puts 'Enter Valid option'
|
|
49
50
|
end
|
|
50
51
|
end
|
|
51
52
|
end
|
data/lib/shopgem/booksdb.rb
CHANGED
|
@@ -5,12 +5,15 @@ class Shopgem::BookDb
|
|
|
5
5
|
|
|
6
6
|
@books=[]
|
|
7
7
|
@karts=[]
|
|
8
|
+
@ttl_books=0
|
|
9
|
+
@books_in_kart=0
|
|
8
10
|
|
|
9
11
|
bFile = File.open("booksdb.txt", "a+")
|
|
10
12
|
if bFile
|
|
11
13
|
arr = IO.readlines("booksdb.txt")
|
|
12
14
|
i = 0
|
|
13
15
|
while(i < arr.length-1)
|
|
16
|
+
@ttl_books +=1
|
|
14
17
|
details = []
|
|
15
18
|
bcode = (arr[i]).to_i
|
|
16
19
|
details.push bcode
|
|
@@ -18,7 +21,7 @@ class Shopgem::BookDb
|
|
|
18
21
|
details.push bname
|
|
19
22
|
bprice = (arr[i+2]).chomp
|
|
20
23
|
details.push bprice
|
|
21
|
-
bqnty = (arr[i+3]).
|
|
24
|
+
bqnty = (arr[i+3]).to_i
|
|
22
25
|
details.push bqnty
|
|
23
26
|
@books << details
|
|
24
27
|
i+=4
|
|
@@ -45,22 +48,34 @@ class Shopgem::BookDb
|
|
|
45
48
|
details.push bname
|
|
46
49
|
puts 'Enter Price'
|
|
47
50
|
bprice = gets.to_i
|
|
51
|
+
if bprice < 1
|
|
52
|
+
puts 'Enter price greater than 0'
|
|
53
|
+
return
|
|
54
|
+
end
|
|
48
55
|
details.push bprice
|
|
49
56
|
puts 'Enter Quantity'
|
|
50
57
|
bqnty = gets.to_i
|
|
58
|
+
if bqnty < 1
|
|
59
|
+
puts 'Enter quantity greater than 0'
|
|
60
|
+
return
|
|
61
|
+
end
|
|
51
62
|
details.push bqnty
|
|
52
63
|
@books << details
|
|
53
64
|
|
|
65
|
+
@ttl_books +=1
|
|
54
66
|
add_to_database
|
|
67
|
+
|
|
55
68
|
end
|
|
56
69
|
|
|
57
70
|
def showBooks
|
|
58
71
|
|
|
59
|
-
puts "srno code
|
|
72
|
+
puts "srno code BookName Price Quantity"
|
|
60
73
|
i=0
|
|
61
74
|
@books.each do |book|
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
|
|
76
|
+
print (i+=1)
|
|
77
|
+
print" "+book[0].to_s+" "+book[1].to_s+" "+book[2].to_s+" "+book[3].to_s+"\n"
|
|
78
|
+
|
|
64
79
|
end
|
|
65
80
|
puts
|
|
66
81
|
end
|
|
@@ -75,20 +90,33 @@ class Shopgem::BookDb
|
|
|
75
90
|
choice = gets.to_i
|
|
76
91
|
puts 'Enter Quantity'
|
|
77
92
|
qnt = gets.to_i
|
|
93
|
+
if (choice > @ttl_books)
|
|
94
|
+
puts "Enter Valid Number"
|
|
95
|
+
return
|
|
96
|
+
end
|
|
97
|
+
if @books[choice-1][3].to_i === 0
|
|
98
|
+
puts ' ** book is out of stock '
|
|
99
|
+
elsif @books[choice-1][3].to_i < qnt && qnt > 0
|
|
100
|
+
puts ' ** Enter valid quantity '+ @books[choice-1][3].to_s
|
|
101
|
+
else
|
|
102
|
+
kart[0] = @books[choice - 1][0]
|
|
103
|
+
kart[1] = @books[choice-1][1]
|
|
104
|
+
kart[2] = @books[choice-1][2]
|
|
105
|
+
kart[3] = qnt
|
|
106
|
+
@karts.push kart
|
|
107
|
+
@books[choice-1][3] = (@books[choice-1][3]).to_i - qnt
|
|
108
|
+
puts @books[choice-1][1].to_s + " Added to cart "
|
|
109
|
+
|
|
110
|
+
puts 'Do you wnt to add more books in your cart y/n'
|
|
111
|
+
chh=gets.chomp
|
|
112
|
+
if chh === 'y' || chh ==='Y'
|
|
113
|
+
add_to_kart
|
|
114
|
+
end
|
|
115
|
+
#add_to_database
|
|
116
|
+
end
|
|
117
|
+
|
|
78
118
|
|
|
79
|
-
kart[0] = @books[choice - 1][0]
|
|
80
|
-
kart[1] = @books[choice-1][1]
|
|
81
|
-
kart[2] = @books[choice-1][2]
|
|
82
|
-
kart[3] = qnt
|
|
83
|
-
@karts.push kart
|
|
84
119
|
|
|
85
|
-
if @books[choice-1][3].to_i < qnt
|
|
86
|
-
puts ' ** Enter quantity less than '+ @books[choice-1][3]
|
|
87
|
-
else
|
|
88
|
-
@books[choice-1][3] = (@books[choice-1][3]).to_i - qnt
|
|
89
|
-
puts @books[choice-1][1] + " Added to cart "
|
|
90
|
-
#add_to_database
|
|
91
|
-
end
|
|
92
120
|
#if @books[choice-1][3]==0
|
|
93
121
|
|
|
94
122
|
#end
|
|
@@ -100,6 +128,7 @@ class Shopgem::BookDb
|
|
|
100
128
|
puts "srno code Book Name Price Quantity"
|
|
101
129
|
i = 0
|
|
102
130
|
@karts.each do |book|
|
|
131
|
+
@books_in_kart +=1
|
|
103
132
|
print "\n"+(i+=1).to_s+" "+book[0].to_s+" "+book[1].to_s+" "+book[2].to_s+" "+book[3].to_s
|
|
104
133
|
end
|
|
105
134
|
puts
|
|
@@ -108,7 +137,12 @@ class Shopgem::BookDb
|
|
|
108
137
|
def remove_from_kart
|
|
109
138
|
showKart
|
|
110
139
|
puts 'Enter the book to remove from kart'
|
|
111
|
-
|
|
140
|
+
choice = gets.to_i
|
|
141
|
+
if (choice > @books_in_kart)
|
|
142
|
+
puts "Enter Valid Number"
|
|
143
|
+
|
|
144
|
+
else
|
|
145
|
+
|
|
112
146
|
code = @karts[choice-1][1]
|
|
113
147
|
|
|
114
148
|
i=0
|
|
@@ -119,9 +153,9 @@ class Shopgem::BookDb
|
|
|
119
153
|
i+=1
|
|
120
154
|
end
|
|
121
155
|
@karts[choice-1][3] = (@karts[choice-1][3]).to_i - 1
|
|
156
|
+
showKart
|
|
157
|
+
end
|
|
122
158
|
|
|
123
|
-
|
|
124
|
-
showKart
|
|
125
159
|
end
|
|
126
160
|
|
|
127
161
|
def checkout
|
|
@@ -151,17 +185,22 @@ class Shopgem::BookDb
|
|
|
151
185
|
showBooks
|
|
152
186
|
puts 'Enter sr no to update book'
|
|
153
187
|
ch=(gets.to_i)-1
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
188
|
+
if (ch >= @ttl_books)
|
|
189
|
+
puts "Enter Valid Number"
|
|
190
|
+
else
|
|
191
|
+
puts 'current name :'+ @books[ch][1]
|
|
192
|
+
puts 'enter new name:'
|
|
193
|
+
@books[ch][1]=gets.chomp
|
|
194
|
+
puts 'current price :'+ (@books[ch][2]).to_s
|
|
195
|
+
puts 'enter new price:'
|
|
196
|
+
@books[ch][2]=gets.to_i
|
|
197
|
+
puts 'current Quantity :'+ (@books[ch][3]).to_s
|
|
198
|
+
puts 'enter new Quantity:'
|
|
199
|
+
@books[ch][3]=gets.to_i
|
|
200
|
+
puts"Data Updated"
|
|
201
|
+
add_to_database
|
|
202
|
+
end
|
|
203
|
+
|
|
165
204
|
end
|
|
166
205
|
|
|
167
206
|
def delete
|
|
@@ -169,8 +208,13 @@ class Shopgem::BookDb
|
|
|
169
208
|
showBooks
|
|
170
209
|
puts 'Enter sr no to delete book'
|
|
171
210
|
ch = (gets.to_i)-1
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
211
|
+
if (ch >= @ttl_books)
|
|
212
|
+
puts "Enter Valid Number"
|
|
213
|
+
else
|
|
214
|
+
@books.delete_at(ch)
|
|
215
|
+
puts 'book deleted'
|
|
216
|
+
add_to_database
|
|
217
|
+
end
|
|
218
|
+
|
|
175
219
|
end
|
|
176
220
|
end
|