Class: KindleManager::BaseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kindle_manager/parsers/base_parser.rb

Direct Known Subclasses

BooksParser, HighlightsParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath, options = {}) ⇒ BaseParser

Returns a new instance of BaseParser.



5
6
7
8
9
10
11
12
13
# File 'lib/kindle_manager/parsers/base_parser.rb', line 5

def initialize(filepath, options = {})
  @filepath = filepath

  @fetched_at = if File.basename(@filepath) =~ /\A\d{14}/
    Time.strptime(File.basename(@filepath)[0..14], KindleManager::FileStore::TIME_FORMAT_FOR_FILENAME)
  else
    File.ctime(@filepath)
  end
end

Instance Attribute Details

#fetched_atObject

Returns the value of attribute fetched_at.



3
4
5
# File 'lib/kindle_manager/parsers/base_parser.rb', line 3

def fetched_at
  @fetched_at
end

Instance Method Details

#bodyObject



19
20
21
# File 'lib/kindle_manager/parsers/base_parser.rb', line 19

def body
  @body ||= File.read(@filepath)
end

#docObject



15
16
17
# File 'lib/kindle_manager/parsers/base_parser.rb', line 15

def doc
  @doc ||= Nokogiri::HTML(body)
end