Class: Repub::App::Parser::ParserSupport
- Includes:
- Logger
- Defined in:
- lib/repub/app/parser.rb
Defined Under Namespace
Classes: TocItem
Constant Summary
Constants included from Logger
Logger::LOGGER_NORMAL, Logger::LOGGER_QUIET, Logger::LOGGER_VERBOSE
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#toc ⇒ Object
readonly
Returns the value of attribute toc.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
-
#initialize(options) ⇒ ParserSupport
constructor
A new instance of ParserSupport.
-
#parse(cache) ⇒ Object
Parse downloaded asset cache.
Methods included from Logger
Constructor Details
#initialize(options) ⇒ ParserSupport
Returns a new instance of ParserSupport.
32 33 34 |
# File 'lib/repub/app/parser.rb', line 32 def initialize() @selectors = [:selectors] || Selectors end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
27 28 29 |
# File 'lib/repub/app/parser.rb', line 27 def cache @cache end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
29 30 31 |
# File 'lib/repub/app/parser.rb', line 29 def title @title end |
#toc ⇒ Object (readonly)
Returns the value of attribute toc.
30 31 32 |
# File 'lib/repub/app/parser.rb', line 30 def toc @toc end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
28 29 30 |
# File 'lib/repub/app/parser.rb', line 28 def uid @uid end |
Instance Method Details
#parse(cache) ⇒ Object
Parse downloaded asset cache
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/repub/app/parser.rb', line 38 def parse(cache) raise ParserException, "No HTML document found" if cache.assets[:documents].empty? # TODO: limited to a single document only raise ParserException, "More than one HTML document found, this is not supported (yet)" if cache.assets[:documents].size > 1 @cache = cache @document = @cache.assets[:documents][0] log.debug "-- Parsing #{@document}" @doc = Nokogiri::HTML.parse(IO.read(File.join(@cache.path, @document)), nil, 'UTF-8') @uid = @cache.name parse_title parse_toc self end |