Class: Drom::Search

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/drom/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Search

Returns a new instance of Search.



6
7
8
9
10
11
12
# File 'lib/drom/search.rb', line 6

def initialize(options = {}, &block)
  @start_page = start_page(options)
  @listings = []
  @next_page = nil
  @progress_type = options[:status] || :none
  start(@progress_type, &block) if valid_options?(options)
end

Instance Attribute Details

#listingsObject (readonly)

Returns the value of attribute listings.



4
5
6
# File 'lib/drom/search.rb', line 4

def listings
  @listings
end

Instance Method Details

#<<(listing) ⇒ Object



14
15
16
# File 'lib/drom/search.rb', line 14

def <<(listing)
  @listings << listing
end

#each(&block) ⇒ Object



18
19
20
# File 'lib/drom/search.rb', line 18

def each(&block)
  @listings.each(&block)
end

#to_csvObject



22
23
24
25
26
27
28
29
30
# File 'lib/drom/search.rb', line 22

def to_csv
  csv = CSV.generate do |csv|
    self.listings.uniq.each do |l|
      csv << [l["Ссылка"], l.map {|k,v| "#{k}: #{v}"}.join("\r\n")]
    end
  end
  print "TOTAL #{@listings.size}\n"
  File.write("listings.csv", csv)
end