Class: SellerAPI

Inherits:
Object
  • Object
show all
Extended by:
UserModule
Defined in:
lib/SellerAPI.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from UserModule

get_number, get_string, list_products, search_product

Instance Attribute Details

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/SellerAPI.rb', line 8

def id
  @id
end

#moneyObject

Returns the value of attribute money.



8
9
10
# File 'lib/SellerAPI.rb', line 8

def money
  @money
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/SellerAPI.rb', line 8

def name
  @name
end

#valid_hashObject

Returns the value of attribute valid_hash.



8
9
10
# File 'lib/SellerAPI.rb', line 8

def valid_hash
  @valid_hash
end

Class Method Details

.add_productObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/SellerAPI.rb', line 12

def self.add_product
  puts "Enter product details: ('q' to quit )"

  name = get_string($PRODUCT_FIELD[:name])
  return if name == -1
  color = get_string($PRODUCT_FIELD[:color])
  return if color == -1
  price = get_number($PRODUCT_FIELD[:price])
  return if price == -1
  quantity = get_number($PRODUCT_FIELD[:quantity])
  return if quantity == -1

  product = {name: name, color: color, price: price, quantity: quantity}
  ProductAPI.add(product)
end

.delete_productObject



42
43
44
45
46
47
48
# File 'lib/SellerAPI.rb', line 42

def self.delete_product
  list_products
  print "\n\tEnter product id to be deleted ('q' to quit): "
  id = gets.chomp.to_i
  return if id == -1
  ProductAPI.delete(id)
end

.update_productObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/SellerAPI.rb', line 28

def self.update_product
  list_products
  puts "\n\tEnter the product needed to be updated: ('q' to quit) "

  id = get_number("ID of product")
  return if id == -1
  key = get_string("Update field ")
  return if key == -1
  value = get_string("New value for '#{key}'")
  return if id == -1

  ProductAPI.update(id, key.to_sym, value)
end