Class: LeicaScFinderApp::CameraListItem

Inherits:
Object
  • Object
show all
Defined in:
lib/leica_sc_finder_app/camera_list_item.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#countObject

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

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

#titleObject

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

.allObject



6
7
8
# File 'lib/leica_sc_finder_app/camera_list_item.rb', line 6

def self.all
  @@all
end


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

.scrapeObject



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