shopping2 0.0.1
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 +7 -0
- data/lib/shopping2.rb +237 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 69cf0767d2522d2a729db11411b6cf6c0c97919f
|
|
4
|
+
data.tar.gz: b6257932c363ec7e290c2c30810b81012fb1acd0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ffac0b8c9c3a4c622643dac0eb53103e7a0b6c8bf0a640934aedca6a6b087ce9329f0c242a437d7ffec965bafd0430a52be425d5bb4bc5f73d28896281ad9988
|
|
7
|
+
data.tar.gz: 0b8f6f3827aa91dd02aeb61931b42ca4f1e3fc6125c1d77551fc785a5c169051cbc4079df5b7498c40bcbc2c73a2b65499fdc995d2f430681e39c0413a6cd143
|
data/lib/shopping2.rb
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
|
|
2
|
+
require 'csv'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Shopping
|
|
7
|
+
|
|
8
|
+
@p;
|
|
9
|
+
|
|
10
|
+
@c;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@p = Products.new
|
|
15
|
+
@c = Cart.new
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def displayOptions
|
|
21
|
+
|
|
22
|
+
puts "Select from below"
|
|
23
|
+
|
|
24
|
+
puts "1 Display All Products"
|
|
25
|
+
puts "2 Select Products"
|
|
26
|
+
puts "3 Display Cart"
|
|
27
|
+
puts "4 Checkout"
|
|
28
|
+
puts "\n"
|
|
29
|
+
puts "\n"
|
|
30
|
+
puts "\n"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
choice = gets.chomp
|
|
34
|
+
#puts choice
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
case choice
|
|
38
|
+
when '1'
|
|
39
|
+
@p.displayProducts
|
|
40
|
+
displayOptions
|
|
41
|
+
|
|
42
|
+
when '2'
|
|
43
|
+
puts "Enter product id to buy"
|
|
44
|
+
prod_id = gets.chomp
|
|
45
|
+
puts "Enter quantity of product"
|
|
46
|
+
qty = gets.chomp
|
|
47
|
+
|
|
48
|
+
@c.addToCart(prod_id,qty)
|
|
49
|
+
|
|
50
|
+
puts("Do you want to continue shopping? y/n")
|
|
51
|
+
ans = gets.chomp
|
|
52
|
+
if (ans=='y')
|
|
53
|
+
displayOptions
|
|
54
|
+
else
|
|
55
|
+
@c.displayCart
|
|
56
|
+
displayOptions
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
when '3'
|
|
61
|
+
@c.displayCart
|
|
62
|
+
displayOptions
|
|
63
|
+
|
|
64
|
+
when '4'
|
|
65
|
+
@c.buy
|
|
66
|
+
displayOptions
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class Cart
|
|
78
|
+
|
|
79
|
+
@product_id;
|
|
80
|
+
@quantity;
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def initialize
|
|
84
|
+
CSV.open('Cart.csv', 'ab') do |csv|
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def addToCart (prod_id,qty)
|
|
92
|
+
|
|
93
|
+
productresult = Array.new
|
|
94
|
+
|
|
95
|
+
CSV.foreach('products.csv') do |record|
|
|
96
|
+
|
|
97
|
+
productresult << record
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
productRow= productresult.select{|e| e[0]==prod_id}
|
|
101
|
+
#puts productRow
|
|
102
|
+
|
|
103
|
+
#puts productRow[0][2]
|
|
104
|
+
cost= productRow[0][2].to_i * qty.to_i
|
|
105
|
+
|
|
106
|
+
puts "Cost is "
|
|
107
|
+
puts cost
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
cartrecords=[[productRow[0][1].to_s,qty,cost]]
|
|
111
|
+
|
|
112
|
+
CSV.open('Cart.csv', "ab") do |csv|
|
|
113
|
+
|
|
114
|
+
cartrecords.each {|rec| csv << rec}
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
puts "Product added to your cart"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def displayCart
|
|
124
|
+
cartresult = Array.new
|
|
125
|
+
|
|
126
|
+
CSV.foreach('Cart.csv') do |record|
|
|
127
|
+
|
|
128
|
+
cartresult << record
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
puts "Product Quantity Cost"
|
|
135
|
+
cartresult.each do|item|
|
|
136
|
+
puts item.join " "
|
|
137
|
+
puts"\s"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def buy
|
|
144
|
+
cartItems = Array.new
|
|
145
|
+
|
|
146
|
+
CSV.foreach('Cart.csv') do |record|
|
|
147
|
+
|
|
148
|
+
cartItems << record
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
#puts cartItems
|
|
154
|
+
#puts cartItems[0]
|
|
155
|
+
#puts cartItems[0][0]
|
|
156
|
+
result = Array.new
|
|
157
|
+
|
|
158
|
+
CSV.foreach('products.csv') do |record1|
|
|
159
|
+
|
|
160
|
+
result << record1
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
result.each do |r|
|
|
164
|
+
cartItems.each do |c|
|
|
165
|
+
if r[1]==c[0]
|
|
166
|
+
r[3]=r[3].to_i-c[1].to_i
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
#puts result
|
|
173
|
+
|
|
174
|
+
result.each do|item|
|
|
175
|
+
puts item.join " "
|
|
176
|
+
puts"\n"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# for making cart empty
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
CSV.open('Cart.csv', 'w') do |csv|
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
class Products
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def initialize
|
|
195
|
+
products=[ [1,'Da Vinci Code book', 250, 25],
|
|
196
|
+
[2,'HP laptop', 50000, 10],
|
|
197
|
+
[3,'Hibiscus shampoo', 150, 20],
|
|
198
|
+
[4,'Cotton shirt', 1000, 30]]
|
|
199
|
+
CSV.open('products.csv', 'w') do |csv|
|
|
200
|
+
|
|
201
|
+
products.each {|record| csv << record }
|
|
202
|
+
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
# display the list of available products
|
|
209
|
+
|
|
210
|
+
def displayProducts
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
result = Array.new
|
|
214
|
+
|
|
215
|
+
CSV.foreach('products.csv') do |record|
|
|
216
|
+
|
|
217
|
+
result << record
|
|
218
|
+
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
puts "ID Product Price Qty."
|
|
222
|
+
result.each do|item|
|
|
223
|
+
puts item.join " "
|
|
224
|
+
puts"\n"
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
shop= Shopping.new
|
|
236
|
+
|
|
237
|
+
shop.displayOptions
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: shopping2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tejaswini
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Online Shopping gem
|
|
14
|
+
email: tejuganbawale@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/shopping2.rb
|
|
20
|
+
homepage: http://rubygems.org/gems/shopping
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.5.1
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Assignment 5
|
|
44
|
+
test_files: []
|