Class: Pageflow::Chart::Downloader
- Inherits:
-
Object
- Object
- Pageflow::Chart::Downloader
- Defined in:
- lib/pageflow/chart/downloader.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Downloader
constructor
A new instance of Downloader.
- #load(url) ⇒ Object
- #load_all(urls, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Downloader
Returns a new instance of Downloader.
9 10 11 |
# File 'lib/pageflow/chart/downloader.rb', line 9 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/pageflow/chart/downloader.rb', line 7 def @options end |
Instance Method Details
#load(url) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/pageflow/chart/downloader.rb', line 13 def load(url) file = open(make_absolute(url)) begin yield(file) ensure file.close end end |
#load_all(urls, options = {}) ⇒ Object
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 |
# File 'lib/pageflow/chart/downloader.rb', line 23 def load_all(urls, = {}) file = Tempfile.new(['concatenation', .fetch(:extension, 'txt')]) file.binmode begin urls.map do |url| file.write([:before_each]) if .key?(:before_each) load(url) do |source| while data = source.read(16 * 1024) file.write(data) end end file.write([:after_each]) if .key?(:after_each) file.write(.fetch(:separator, "\n")) end file.rewind yield(file) ensure file.close file.unlink end end |