Class: HashcardsReadwise::Converter
- Inherits:
-
Object
- Object
- HashcardsReadwise::Converter
- Defined in:
- lib/hashcards_readwise/converter.rb
Constant Summary collapse
- DEFAULT_AUTHOR =
"Derek Stride"
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #convert(hashcards_path:, db_path: nil) ⇒ Object
-
#initialize(logger: Logger.new($stderr, level: Logger::WARN)) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(logger: Logger.new($stderr, level: Logger::WARN)) ⇒ Converter
Returns a new instance of Converter.
14 15 16 17 |
# File 'lib/hashcards_readwise/converter.rb', line 14 def initialize(logger: Logger.new($stderr, level: Logger::WARN)) @logger = logger @frontmatter_cache = {} end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/hashcards_readwise/converter.rb', line 12 def logger @logger end |
Instance Method Details
#convert(hashcards_path:, db_path: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hashcards_readwise/converter.rb', line 19 def convert(hashcards_path:, db_path: nil) hashcards = JSON.parse(File.read(hashcards_path)) logger.info("Loaded #{hashcards["cards"].size} cards from #{hashcards_path}") = (db_path) logger.info("Loaded #{.size} timestamps from database") if .any? highlights = hashcards["cards"].filter_map { |card| card_to_highlight(card, ) } logger.info("Converted #{highlights.size} highlights") logger.info("Parsed frontmatter from #{@frontmatter_cache.size} files") { "highlights" => highlights } end |