next unless Book.can_handle?(file)
key = "#{File.dirname(file)}/#{File.basename(file, ".*")}"
- if unique.key?(key)
- new_ext = File.extname(file)
- old_ext = File.extname(unique[key])
- if old_ext == ".pdf" && new_ext == ".epub"
- # Prefer EPUB over PDF
- puts "REPLACED #{unique[key]} with #{file}"
- unique[key] = file
+ unique[key] =
+ if unique.key?(key)
+ preferred_format(old_file: unique[key], new_file: file)
else
- puts "DROPPED #{file} because it's superceded by #{unique[key]}"
+ file
end
- else
- unique[key] = file
- end
end
unique.values
12
end
+ def preferred_format(old_file:, new_file:)
+ new_ext = File.extname(new_file)
+ old_ext = File.extname(old_file)
+ if old_ext == ".pdf" && new_ext == ".epub"
+ # Prefer EPUB over PDF
+ puts "REPLACED #{old_file} with #{new_file}"
+ new_file
+ else
+ puts "DROPPED #{new_file} because it's superseded by #{old_file}"
+ old_file
+ end
+ end
+
def should_descend_into_directory?(path)
child = File.basename(path)
File.directory?(path) && child != "." && child != ".." && !File.symlink?(path)
end
end
+ # rubocop:disable Metrics/AbcSize
def test_load_from_file
@store.expects(:get_series).returns(mock_series_lw)
@store.connect
assert_equal "Louisa May Alcott", author.reading_order
assert_equal "Alcott, Louisa May", author.sort_order
- expected_descr = "This story follows the lives of the four March sisters&emdash;Meg, Jo, Beth, and Amy&emdash;" \
- "and details their coming of age."
+ assert_equal(
+ "This story follows the lives of the four March sisters&emdash;Meg, Jo, Beth, and Amy&emdash;" \
+ "and details their coming of age.",
+ book.description
+ )
- assert_equal expected_descr, book.description
assert_equal "en", book.language
assert_equal "Little Women: Or, Meg, Jo, Beth and Amy", book.title
assert_equal mock_series_lw.to_s, book.series_id.to_s
assert_equal 1, book.volume.to_i
end
+ # rubocop:enable Metrics/AbcSize
def test_heading
@store.expects(:get_series).returns(mock_series_lw)