Class: LittleFish::Fisher

Inherits:
Object
  • Object
show all
Defined in:
lib/little_fish/fisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFisher

Returns a new instance of Fisher.



11
12
13
14
15
16
17
18
19
20
# File 'lib/little_fish/fisher.rb', line 11

def initialize
  if block_given?
    yield self
  else
    @url = 'http://feeds.boston.com/boston/bigpicture/index'
    @last_nth_item = 0
    @dumpfile = './pic_output_' + Time.now.strftime('%H-%M-%S') + '.txt'
    @download = false
  end
end

Instance Attribute Details

#download=(value) ⇒ Object

Sets the attribute download

Parameters:

  • value

    the value to set the attribute download to.



10
11
12
# File 'lib/little_fish/fisher.rb', line 10

def download=(value)
  @download = value
end

#dumpfileObject

Returns the value of attribute dumpfile.



10
11
12
# File 'lib/little_fish/fisher.rb', line 10

def dumpfile
  @dumpfile
end

#last_nth_itemObject

Returns the value of attribute last_nth_item.



10
11
12
# File 'lib/little_fish/fisher.rb', line 10

def last_nth_item
  @last_nth_item
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/little_fish/fisher.rb', line 10

def url
  @url
end

Instance Method Details

#pullObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/little_fish/fisher.rb', line 22

def pull
  info 'opening URI ... '
  rss_string = open_url(@url)

  info 'parsing doc from text ... '
  doc  = get_doc(rss_string, @last_nth_item)

  info 'filling doc into bp_info ... '
  bp_info  = get_bp_info(doc)

  unless ['none', 'NONE', 'no', 'NO', 'false', 'FALSE'].include? @dumpfile
    info 'dumping bp_info ... '
    f = File.new(@dumpfile, 'w') 
    bp_info[:images].each do |img|
      f.puts img
    end
    info 'saved info in ' +  @dumpfile
  end

  if @download
    info 'down loading photos ... '
    urls = bp_info[:images].map{|img| img[:url]}
    download(urls, 'lf_download')
    info 'photos downloaded!'
  end

  bp_info
end