Class: NeweggScraperChsbr::Cpu

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, price, shipping, desc) ⇒ Cpu

Returns a new instance of Cpu.



5
6
7
8
9
10
11
# File 'lib/newegg_scraper_chsbr/cpu.rb', line 5

def initialize(name, price, shipping, desc)
    @name = NeweggScraperChsbr::Name.new(name)
    @price = NeweggScraperChsbr::Price.new(price)
    @desc = NeweggScraperChsbr::Descriptors.new(desc)
    @shipping = NeweggScraperChsbr::Shipping.new(shipping)
    @@all << self
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



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

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#priceObject (readonly)

Returns the value of attribute price.



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

def price
  @price
end

#shippingObject (readonly)

Returns the value of attribute shipping.



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

def shipping
  @shipping
end

Class Method Details

.allObject



12
13
14
# File 'lib/newegg_scraper_chsbr/cpu.rb', line 12

def self.all
    @@all
end

.cpu_maker(cpu_make) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/newegg_scraper_chsbr/cpu.rb', line 15

def self.cpu_maker(cpu_make)
    if cpu_make == 'i'
        "Intel"
    elsif cpu_make == 'a'
        "AMD"
    else
        "either Intel or AMD"
    end
end

.display_cpu(user) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/newegg_scraper_chsbr/cpu.rb', line 24

def self.display_cpu(user) 
    counter = 1
    printed_cpus = []
    @@all.each do | computer |
        if user.max_price.to_i != 0 && user.min_price.to_i == 0
            

            user.min_price = "1"
        end
        if user.max_price.to_i == 0 &&
            user.min_price.to_i == 0 &&
            (NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "Intel" || NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "AMD")
                if computer.name.name.include?(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make))
                    puts("\n  #{counter}:\n     Name: #{computer.name.name}\n     Price: #{computer.price.price}")
                    printed_cpus << counter
                else
                    nil
                end
        elsif user.max_price.to_i == 0 && user.min_price.to_i == 0 && user.cpu_make == 'x'
                
                puts("\n   #{counter}:\n     Name: #{computer.name.name}\n     Price: #{computer.price.price}")
                printed_cpus << counter
        elsif user.max_price.to_i >= computer.price.convert_price &&
            user.min_price.to_i <= computer.price.convert_price &&
            (NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "Intel" || NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make) == "AMD")
                if computer.name.name.include?(NeweggScraperChsbr::Cpu.cpu_maker(user.cpu_make)) 
                    puts("\n  #{counter}:\n     Name: #{computer.name.name}\n     Price: #{computer.price.price}")
                    printed_cpus << counter
                else
                    nil
                end
        
        elsif user.max_price.to_i >= computer.price.convert_price &&
            user.min_price.to_i <= computer.price.convert_price &&
            user.cpu_make == 'x'
                puts("\n  #{counter}:\n     Name: #{computer.name.name}\n     Price: #{computer.price.price}")
                printed_cpus << counter

        end

        counter += 1
        
    end
    if printed_cpus.size == 0
        puts "You did not match any CPU criteria."
    end
    printed_cpus

end

.display_cpu_with_extras(user) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/newegg_scraper_chsbr/cpu.rb', line 73

def self.display_cpu_with_extras(user)
    
    user.chosen_cpu.each do | chosen_cpu |
        puts "\n\n\n#{@@all[chosen_cpu - 1].name.name}\nHas a price of: #{@@all[chosen_cpu - 1].price.price}\nShipping: #{@@all[chosen_cpu - 1].shipping.price}\n\n   Descriptive Points:\n"
        @@all[chosen_cpu - 1].printDesc
    end
end

Instance Method Details

#printDescObject



80
81
82
83
84
# File 'lib/newegg_scraper_chsbr/cpu.rb', line 80

def printDesc
    @desc.bullets.each do | key, value |
        puts "          #{key + 1}: #{value}"
    end
end