Class: NeweggScraperChsbr::User

Inherits:
Object
  • Object
show all
Defined in:
lib/newegg_scraper_chsbr/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cpu_make = 'x', min_price = 0, max_price = 0) ⇒ User

Returns a new instance of User.



4
5
6
7
8
9
# File 'lib/newegg_scraper_chsbr/user.rb', line 4

def initialize(cpu_make = 'x', min_price = 0, max_price = 0)
    @cpu_make = cpu_make
    @min_price = min_price
    @max_price = max_price
    @chosen_cpu = []
end

Instance Attribute Details

#chosen_cpuObject

Returns the value of attribute chosen_cpu.



3
4
5
# File 'lib/newegg_scraper_chsbr/user.rb', line 3

def chosen_cpu
  @chosen_cpu
end

#cpu_makeObject

Returns the value of attribute cpu_make.



3
4
5
# File 'lib/newegg_scraper_chsbr/user.rb', line 3

def cpu_make
  @cpu_make
end

#max_priceObject

Returns the value of attribute max_price.



3
4
5
# File 'lib/newegg_scraper_chsbr/user.rb', line 3

def max_price
  @max_price
end

#min_priceObject

Returns the value of attribute min_price.



3
4
5
# File 'lib/newegg_scraper_chsbr/user.rb', line 3

def min_price
  @min_price
end

Instance Method Details

#choose_cpu(printed_cpus) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/newegg_scraper_chsbr/user.rb', line 11

def choose_cpu(printed_cpus)
    puts "Please enter the number of the CPU you'd like to see more about."
    chosen = gets.strip
    while !is_numeric?(chosen)
        puts "Please enter the number of the CPU you'd like to see more about."
        chosen = gets.strip
    end
    if !printed_cpus.include?(chosen.to_i)
        puts "You chose a CPU outside of your budget please choose another."
        choose_cpu(printed_cpus)
    end
    @chosen_cpu << chosen.to_i
    puts "Would you like to see more about another CPU?\nEnter y to do so.\nEnter n to see details about the chosen CPU(s)"
        input = gets.strip
        
    if input == 'y'
        choose_cpu(printed_cpus)
    end
    
end

#clear_chosenObject



31
32
33
# File 'lib/newegg_scraper_chsbr/user.rb', line 31

def clear_chosen
    @chosen_cpu = []
end

#is_numeric?(obj) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/newegg_scraper_chsbr/user.rb', line 34

def is_numeric?(obj) 
   obj.match(/\A[^+-]?\d+?(\^.\d+)?\Z/) == nil ? false : true
end