Module: Scruber::Core::PageFormat

Defined in:
lib/scruber/core/page_format.rb,
lib/scruber/core/page_format/xml.rb,
lib/scruber/core/page_format/base.rb,
lib/scruber/core/page_format/html.rb,
lib/scruber/core/page_format/json.rb

Defined Under Namespace

Classes: Base, HTML, Json, XML

Class Method Summary collapse

Class Method Details

.[](label) ⇒ Object



23
24
25
# File 'lib/scruber/core/page_format.rb', line 23

def [](label)
  _registered_formats[label]
end

._registered_formatsObject



27
28
29
# File 'lib/scruber/core/page_format.rb', line 27

def _registered_formats
  @registered_formats ||= {}
end

.add(label, claz) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/scruber/core/page_format.rb', line 15

def add(label, claz)
  unless claz.respond_to?(:process)
    raise NoMethodError, "process is not declared in the #{claz.inspect}"
  end

  _registered_formats[label] = claz
end

.process(page, page_format) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/scruber/core/page_format.rb', line 5

def process(page, page_format)
  if page_format.nil?
    nil
  elsif _registered_formats.keys.include?(page_format.to_sym)
    _registered_formats[page_format.to_sym].process(page)
  else
    raise "Unsupported format"
  end
end