File book.rb
has 376 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'rubygems'
require 'nokogiri'
require 'zip'
require 'fileutils'
Method nav_doc
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def nav_doc(title = 'Table of Contents')
# handle cascaded toc
start_level = @toc && !@toc.empty? && @toc[0][:level] || 1
stacked_toc = {level: start_level, tocs: [] }
@toc.inject(stacked_toc) do |current_stack, toc_entry|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method nav_doc
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
def nav_doc(title = 'Table of Contents')
# handle cascaded toc
start_level = @toc && !@toc.empty? && @toc[0][:level] || 1
stacked_toc = {level: start_level, tocs: [] }
@toc.inject(stacked_toc) do |current_stack, toc_entry|
Class Book
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class Book
include InspectMixin
MIMETYPE='mimetype'
MIMETYPE_CONTENTS='application/epub+zip'
Method write_toc
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def write_toc xml_doc, tocs
return if tocs.empty?
xml_doc.ol {
tocs.each {
|x|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method ncx_xml
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def ncx_xml
builder = Nokogiri::XML::Builder.new {
|xml|
xml.ncx('xmlns' => 'http://www.daisy.org/z3986/2005/ncx/', 'version' => '2005-1') {
xml.head {
Method write_to_epub_container
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def write_to_epub_container(epub)
mod_time = Zip::DOSTime.now
unless (last_mod = lastmodified).nil?
tm = last_mod.content
mod_time = Zip::DOSTime.local(tm.year, tm.month, tm.day, tm.hour, tm.min, tm.sec)
Method add_item_internal
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def add_item_internal(href, content: nil, item_attributes: , attributes: {}, ordered: )
id = item_attributes.delete(:id)
item =
if ordered
@package.add_ordered_item(href,attributes: attributes, id:id, content: content)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method handle_deprecated_add_item_arguments
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
if deprecated_content
msg = 'deprecated argument; use content keyword argument instead of 2nd argument'
fail msg if content
warn msg
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parse_container
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.parse_container(zip_file, files)
package_path = nil
package = nil
zip_file.each do |entry|
if !entry.directory?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method handle_deprecated_add_item_arguments
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
Method cleanup_for_epub2
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def cleanup_for_epub2
if version.to_f < 3.0 || @package.epub_backward_compat
if @package.manifest.item_list.select {
|_x,item|
item.media_type == 'application/x-dtbncx+xml'
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method cleanup_for_epub3
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def cleanup_for_epub3
if version.to_f >=3.0
@package.metadata.modified_now unless @package.metadata.lastmodified_updated?
if @package.manifest.item_list.select {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method ncx_xml
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def ncx_xml
builder = Nokogiri::XML::Builder.new {
|xml|
xml.ncx('xmlns' => 'http://www.daisy.org/z3986/2005/ncx/', 'version' => '2005-1') {
xml.head {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"