Class: Repub::App::Parser::ParserSupport

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(options) ⇒ ParserSupport

Returns a new instance of ParserSupport.



32
33
34
# File 'lib/repub/app/parser.rb', line 32

def initialize(options)
  @selectors = options[:selectors] || Selectors
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



27
28
29
# File 'lib/repub/app/parser.rb', line 27

def cache
  @cache
end

#titleObject (readonly)

Returns the value of attribute title.



29
30
31
# File 'lib/repub/app/parser.rb', line 29

def title
  @title
end

#tocObject (readonly)

Returns the value of attribute toc.



30
31
32
# File 'lib/repub/app/parser.rb', line 30

def toc
  @toc
end

#uidObject (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

Raises:



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