Class: LeicaScFinderApp::CameraListItem
- Inherits:
-
Object
- Object
- LeicaScFinderApp::CameraListItem
- Defined in:
- lib/leica_sc_finder_app/camera_list_item.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#link ⇒ Object
Returns the value of attribute link.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
2 3 4 |
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 2 def count @count end |
#link ⇒ Object
Returns the value of attribute link.
2 3 4 |
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 2 def link @link end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 2 def title @title end |
Class Method Details
.all ⇒ Object
6 7 8 |
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 6 def self.all @@all end |
.print ⇒ Object
10 11 12 13 14 |
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 10 def self.print all.each.with_index(1) do |item, ind| puts "#{ind}. #{item.title}, count: #{item.count}" end end |
.scrape ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 16 def self.scrape @doc = Nokogiri::HTML(open("http://www.leicashop.com/vintage_en/leica/leica-screw-mount-cameras.html?listview=1")) @doc.search("table.data-table.table-bordered td").each do |row| list_item = LeicaScFinderApp::CameraListItem.new list_item.title = row.search("a").attribute("title").text list_item.count = row.search("a").text[1..-1].match(/\d/)[0] list_item.link = row.search("a").attr("href").value self.all << list_item end end |