Module: UserModule
Instance Method Summary collapse
- #get_number(label) ⇒ Object
- #get_string(label) ⇒ Object
- #list_products ⇒ Object
- #search_product ⇒ Object
Instance Method Details
#get_number(label) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/UserModule.rb', line 19 def get_number(label) print "\tEnter #{label}: " value = gets.chomp if !!(value =~ /[0-9]+/ && value.length == value.match(/[0-9]+/).to_s.length ) return value.to_i elsif value == 'q' return -1 else puts "\tInvalid #{label} value. Try again." return self.get_number(label) end end |
#get_string(label) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/UserModule.rb', line 32 def get_string(label) print "\tEnter #{label}: " value = gets.chomp if !(value.strip.empty?) return value elsif value == 'q' return -1 else puts "\tInvalid #{label} value. Try again." return self.get_string(label) end end |
#list_products ⇒ Object
4 5 6 7 |
# File 'lib/UserModule.rb', line 4 def list_products system 'clear' puts ProductAPI.get_list end |
#search_product ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/UserModule.rb', line 9 def search_product list_products print "\n" key = get_string("product by? 'name' | 'id' | 'color' ") return if key == -1 value = get_string("search value for '#{key}' ") return if value == -1 puts ProductAPI.search(key.to_sym, value) end |