Class: WebCrawler::View::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/web_crawler/view.rb

Direct Known Subclasses

Csv, Json, Plain, Runner, Table, Xml, Yaml

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options = { }) ⇒ Base

Returns a new instance of Base.



30
31
32
33
# File 'lib/web_crawler/view.rb', line 30

def initialize(input, options = { })
  @options = self.class.default_options.merge (options || { })
  @input   = input
end

Class Attribute Details

.default_optionsObject

Returns the value of attribute default_options.



23
24
25
# File 'lib/web_crawler/view.rb', line 23

def default_options
  @default_options
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



18
19
20
# File 'lib/web_crawler/view.rb', line 18

def input
  @input
end

Instance Method Details

#draw(output = nil) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/web_crawler/view.rb', line 39

def draw(output=nil)
  begin
    io = present_output(output)
    io.puts render
  ensure
    io.close if io.respond_to? :close
  end
end

#format(item) ⇒ Object



48
49
50
# File 'lib/web_crawler/view.rb', line 48

def format(item)
  item
end

#renderObject



35
36
37
# File 'lib/web_crawler/view.rb', line 35

def render
  [*input].map { |i| format(i) }.join
end