Class: UrlFinder::Reader
- Inherits:
-
Object
- Object
- UrlFinder::Reader
- 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
-
#content ⇒ Object
readonly
The raw content.
Instance Method Summary collapse
-
#file_format ⇒ String
Returns the file format.
-
#initialize(content, file_format) ⇒ Reader
constructor
Instansiates reader.
-
#urls ⇒ BaseReader
Returns the appropriate reader for the given file format or raises error.
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
#content ⇒ Object (readonly)
The raw content
22 23 24 |
# File 'lib/url_finder/reader.rb', line 22 def content @content end |
Instance Method Details
#file_format ⇒ String
Returns the file format
32 33 34 |
# File 'lib/url_finder/reader.rb', line 32 def file_format @file_format.to_s.downcase end |
#urls ⇒ BaseReader
Returns the appropriate reader for the given file format or raises error
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 |