Class: Knitpickr::Yarn
- Inherits:
-
Object
- Object
- Knitpickr::Yarn
- Defined in:
- lib/knitpickr/yarn.rb
Instance Attribute Summary collapse
-
#fiber ⇒ Object
Returns the value of attribute fiber.
-
#name ⇒ Object
Returns the value of attribute name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#sale ⇒ Object
Returns the value of attribute sale.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
- .find_by_fiber(fiber) ⇒ Object
- .find_by_name(name) ⇒ Object
- .find_by_sale(yarn) ⇒ Object
- .find_by_weight(weight) ⇒ Object
- .show_details(selection) ⇒ Object
Instance Method Summary collapse
-
#initialize(name) ⇒ Yarn
constructor
A new instance of Yarn.
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
#fiber ⇒ Object
Returns the value of attribute fiber.
2 3 4 |
# File 'lib/knitpickr/yarn.rb', line 2 def fiber @fiber end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/knitpickr/yarn.rb', line 2 def name @name end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/knitpickr/yarn.rb', line 2 def price @price end |
#sale ⇒ Object
Returns the value of attribute sale.
2 3 4 |
# File 'lib/knitpickr/yarn.rb', line 2 def sale @sale end |
#weight ⇒ Object
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 |