lib/epub/parser.rb in epub-parser-0.4.1 vs lib/epub/parser.rb in epub-parser-0.4.2

- old
+ new

@@ -10,18 +10,18 @@ # @example # EPUB::Parser.parse('path/to/book.epub') # => EPUB::Book object # # @example # class MyBook - # include EPUB + # include EPUB::Book::Feature # end # book = MyBook.new - # parsed_book = EPUB::Parser.parse('path/to/book.epub', :book => book) # => #<MyBook:0x000000019760e8 @epub_file=..> + # parsed_book = EPUB::Parser.parse('path/to/book.epub', book: book) # => #<MyBook:0x000000019760e8 @epub_file=..> # parsed_book.equal? book # => true # # @example - # book = EPUB::Parser.parse('path/to/book.epub', :class => MyBook) # => #<MyBook:0x000000019b0568 @epub_file=...> + # book = EPUB::Parser.parse('path/to/book.epub', class: MyBook) # => #<MyBook:0x000000019b0568 @epub_file=...> # book.instance_of? MyBook # => true # # @param [String] filepath # @param [Hash] options the type of return is specified by this argument. # If no options, returns {EPUB::Book} object. @@ -33,25 +33,25 @@ # If omitted, {EPUB::OCF::PhysicalContainer.adapter} is used. # @return [EPUB] object which is an instance of class including {EPUB} module. # When option :book passed, returns the same object whose attributes about EPUB are set. # When option :class passed, returns the instance of the class. # Otherwise returns {EPUB::Book} object. - def parse(filepath, **options) - new(filepath, options).parse + def parse(filepath, container_adapter: nil, book: nil, initialize_with: nil, **options) + new(filepath, container_adapter: container_adapter, book: book, initialize_with: initialize_with, **options).parse end end - def initialize(filepath, **options) - path_is_uri = (options[:container_adapter] == EPUB::OCF::PhysicalContainer::UnpackedURI or - options[:container_adapter] == :UnpackedURI or + def initialize(filepath, container_adapter: nil, book: nil, initialize_with: nil, **options) + path_is_uri = (container_adapter == EPUB::OCF::PhysicalContainer::UnpackedURI or + container_adapter == :UnpackedURI or EPUB::OCF::PhysicalContainer.adapter == EPUB::OCF::PhysicalContainer::UnpackedURI) raise "File #{filepath} not found" if !path_is_uri and !File.exist?(filepath) @filepath = path_is_uri ? filepath : File.realpath(filepath) - @book = create_book(options) + @book = create_book(book: book, initialize_with: initialize_with, **options) if path_is_uri @book.container_adapter = :UnpackedURI elsif File.directory? @filepath @book.container_adapter = :UnpackedDirectory end @@ -75,16 +75,16 @@ @book end private - def create_book(params) + def create_book(book: nil, initialize_with: nil, **params) case - when params[:book] - params[:book] + when book + book when params[:class] - if params[:initialize_with] - params[:class].new params[:initialize_with] + if initialize_with + params[:class].new initialize_with else params[:class].new end else Book.new