Sha256: b0cfaaeb55384018636358822ba5a2be3575a6a8734bae455828561d1713f268

Contents?: true

Size: 822 Bytes

Versions: 2

Compression:

Stored size: 822 Bytes

Contents

# encoding: UTF-8

module Klipbook
  module Sources
    module KindleDevice
      class FileParser
        def initialize(entry_parser=EntryParser.new)
          @entry_parser = entry_parser
        end

        def extract_entries(file_text)
          entries_text = split_into_raw_entries_text(file_text)

          build_entries(entries_text)
        end

        private

        def build_entries(entries_text)
          entries_text.map do |entry_text|
            @entry_parser.build_entry(entry_text)
          end.compact
        end

        def strip_control_characters(file_text)
          file_text.gsub("\r", '').gsub("\xef\xbb\xbf", '')
        end

        def split_into_raw_entries_text(file_text)
          strip_control_characters(file_text).split('==========')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
klipbook-4.0.0 lib/klipbook/sources/kindle_device/file_parser.rb
klipbook-3.0.0 lib/klipbook/sources/kindle_device/file_parser.rb