Class: UrlFinder::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/url_finder/reader.rb

Overview

Handles reader delegatation

Constant Summary collapse

FORMAT_READERS =
{
  'markdown' => MarkdownReader,
  'md' => MarkdownReader,
  'html' => HTMLReader,
  'sitemap' => SitemapReader,
  'sitemap.xml' => SitemapReader,
  'string' => StringReader,
  'txt' => StringReader,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, file_format) ⇒ Reader

Instansiates reader



25
26
27
28
# File 'lib/url_finder/reader.rb', line 25

def initialize(content, file_format)
  @content = content
  @file_format = file_format
end

Instance Attribute Details

#contentObject (readonly)

The raw content



22
23
24
# File 'lib/url_finder/reader.rb', line 22

def content
  @content
end

Instance Method Details

#file_formatString

Returns the file format

Returns:

  • (String)

    the file format



32
33
34
# File 'lib/url_finder/reader.rb', line 32

def file_format
  @file_format.to_s.downcase
end

#urlsBaseReader

Returns the appropriate reader for the given file format or raises error

Returns:



38
39
40
41
42
43
# File 'lib/url_finder/reader.rb', line 38

def urls
  reader_klass = FORMAT_READERS.fetch(file_format) do
    raise(ArgumentError, "unknown format #{file_format}")
  end
  reader_klass.new(content)
end