Class: Knitpickr::Yarn

Inherits:
Object
  • Object
show all
Defined in:
lib/knitpickr/yarn.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Yarn

Returns a new instance of Yarn.



5
6
7
8
# File 'lib/knitpickr/yarn.rb', line 5

def initialize(name)
  @name = name
  @sale = nil
end

Instance Attribute Details

#fiberObject

Returns the value of attribute fiber.



2
3
4
# File 'lib/knitpickr/yarn.rb', line 2

def fiber
  @fiber
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/knitpickr/yarn.rb', line 2

def name
  @name
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/knitpickr/yarn.rb', line 2

def price
  @price
end

#saleObject

Returns the value of attribute sale.



2
3
4
# File 'lib/knitpickr/yarn.rb', line 2

def sale
  @sale
end

#weightObject

Returns the value of attribute weight.



2
3
4
# File 'lib/knitpickr/yarn.rb', line 2

def weight
  @weight
end

Class Method Details

.find_by_fiber(fiber) ⇒ Object



18
19
20
# File 'lib/knitpickr/yarn.rb', line 18

def self.find_by_fiber(fiber)
  Knitpickr::Scraper.all_yarns.select {|yarn| yarn.fiber == fiber}
end

.find_by_name(name) ⇒ Object



14
15
16
# File 'lib/knitpickr/yarn.rb', line 14

def self.find_by_name(name)
  Knitpickr::Scraper.all_yarns.select {|yarn| yarn.name == name}
end

.find_by_sale(yarn) ⇒ Object



22
23
24
# File 'lib/knitpickr/yarn.rb', line 22

def self.find_by_sale(yarn)
  Knitpickr::Scraper.all_yarns.select {|yarn| yarn.sale == true}
end

.find_by_weight(weight) ⇒ Object



10
11
12
# File 'lib/knitpickr/yarn.rb', line 10

def self.find_by_weight(weight)
  Knitpickr::Scraper.all_yarns.select {|yarn| yarn.weight == weight}
end

.show_details(selection) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/knitpickr/yarn.rb', line 26

def self.show_details(selection)
  selection.each do |yarn|
    puts
    puts "Yarn name: #{yarn.name}"
    puts "Yarn weight: #{yarn.weight}"
    puts "Fiber content: #{yarn.fiber}"
    puts "Price: #{yarn.price}"
    if yarn.sale
      puts "On sale!"
    end
    puts "___________________________"
  end

end