From: Chris Jaekl Date: Sat, 22 Jun 2024 02:38:13 +0000 (-0400) Subject: Now that we have unit tests in place, clean up style X-Git-Url: https://jaekl.net/gitweb/?a=commitdiff_plain;h=5d7e827f07c625b0248803d68ef2daf881804975;p=quanlib.git Now that we have unit tests in place, clean up style --- diff --git a/app/author.rb b/app/author.rb index fb2003b..781969c 100644 --- a/app/author.rb +++ b/app/author.rb @@ -1,5 +1,10 @@ +# frozen_string_literal: true class Author + attr_accessor :grouping + attr_accessor :reading_order + attr_accessor :sort_order + def initialize(grouping, reading_order, sort_order) @grouping = grouping @reading_order = reading_order @@ -10,39 +15,22 @@ class Author end end - def grouping - @grouping - end - - def reading_order - @reading_order - end - - def sort_order - @sort_order - end - def inspect - result = '(Author:' - if nil != @grouping - result += ' grouping="' + @grouping + '"' - end - if nil != @reading_order - result += ' reading_order="' + @reading_order + '"' - end - if nil != @sort_order - result += ' sort_order="' + @sort_order + '"' - end - result += ')' + field_info = [ + grouping.nil? ? nil : "grouping=\"#{grouping}\"", + reading_order.nil? ? nil : "reading_order=\"#{reading_order}\"", + sort_order.nil? ? nil : "sort_order=\"#{sort_order}\"", + ].compact.join(" ") - return result + "(Author: #{field_info})" end def to_s inspect end - protected + private + def reading_to_sort_order(reading_order) sort_order = reading_order diff --git a/app/book.rb b/app/book.rb index 8c41067..c4d7070 100644 --- a/app/book.rb +++ b/app/book.rb @@ -104,26 +104,16 @@ class Book end def inspect - data = [] - if nil != @author - data.push('author="' + @author.inspect + '"') - end - if nil != @series_id - data.push('series_id="' + @series_id.to_s() + '"') - end - if nil != @volume - data.push('volume="' + @volume + '"') - end - if nil != @title - data.push('title="' + @title + '"') - end - if nil != @cover - data.push(@cover.inspect()) - end - if nil != @path - data.push('path="' + @path + '"') - end - return '(Book:' + data.join(',') + ')' + field_info = [ + author.nil? ? nil : "author=\"#{author.inspect}", + series_id.nil? ? nil : "series_id=\"#{series_id.inspect}", + volume.nil? ? nil : "volume=\"#{volume.inspect}", + title.nil? ? nil : "title=\"#{title.inspect}", + cover.nil? ? nil : "cover=\"#{cover.inspect}", + path.nil? ? nil : "path=\"#{path.inspect}", + ].compact.join(" ") + + return "(Book: #{field_info})" end def to_s @@ -131,19 +121,17 @@ class Book end def title_grouping - if nil == @path - return nil - end + return if path.nil? - return File.basename(@path, '.*') + File.basename(@path, '.*') end - protected + private + def isUpper?(c) - return /[[:upper:]]/.match(c) + /[[:upper:]]/.match(c) end - protected def massage_author(input) if nil == input return nil @@ -157,11 +145,10 @@ class Book reading_order += c end - return reading_order + reading_order end # Returns (series, volumeNo, titleText) - protected def processTitle(input) if nil == input return nil @@ -200,7 +187,6 @@ class Book return series, vol, title end - protected def parse_file_name!(file_name) category = nil # e.g., non-fiction, fan-fiction grouping = '' @@ -237,7 +223,6 @@ class Book end end - protected def scanEpub!(fileName) #puts 'Scanning "' + fileName.to_s + '"...' begin @@ -261,10 +246,7 @@ class Book end end - protected def scan_pdf!(file_name) - #puts 'Scanning "' + file_name.to_s + '"...' - pdf_path = File.expand_path(file_name).to_s if ! pdf_path.end_with?('.pdf') puts 'Unexpected internal error: path "' + file_name.to_s + '" does not end with ".pdf".' @@ -279,8 +261,6 @@ class Book end end - - protected def scanOpf!(zipfile, opfPath) coverId = nil @@ -370,7 +350,6 @@ class Book @cover = load_cover(zipfile, opfPath, opfDoc, coverId) end - protected def load_cover(zipfile, opfPath, opfDoc, coverId) if nil == coverId coverId = "cover-image" @@ -414,7 +393,8 @@ class Book end end end - return nil + + nil end end diff --git a/app/book_loader.rb b/app/book_loader.rb index 5516f04..07eb853 100644 --- a/app/book_loader.rb +++ b/app/book_loader.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative 'book' require_relative 'store' diff --git a/app/classification.rb b/app/classification.rb index 1fb7e12..5eb6f7f 100644 --- a/app/classification.rb +++ b/app/classification.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true class Classification + attr_accessor :id, :ddc, :lcc, :author_grouping, :author, :title_grouping, :title + def initialize(ddc, lcc, author_grouping, author, title_grouping, title) @id = nil @ddc = ddc @@ -10,56 +13,25 @@ class Classification @title = title end - def id - @id - end - def id=(value) - @id = value - end - - def ddc - @ddc - end - def lcc - @lcc - end - def author_grouping - @author_grouping - end - def author - @author - end - def inspect - data = [] - - if nil != @ddc - data.push('Dewey=' + @ddc.to_s.inspect) - end - if nil != @lcc - data.push('LCC=' + @lcc.to_s.inspect) - end - if nil != @author_grouping - data.push('author_grouping=' + @author_grouping.to_s.inspect) - end - if nil != @author - data.push('author=' + @author.to_s.inspect) - end - if nil != @title_grouping - data.push('title_grouping=' + @title_grouping.to_s.inspect) - end - if nil != @title - data.push('title=' + @title.inspect) - end + field_info = [ + ddc.nil? ? nil : "Dewey=#{ddc.inspect}", + lcc.nil? ? nil : "LCC=#{lcc.inspect}", + author_grouping.nil? ? nil : "author_grouping=#{author_grouping.inspect}", + author.nil? ? nil : "author=#{author.inspect}", + title_grouping.nil? ? nil : "title_grouping=#{title_grouping.inspect}", + title.nil? ? nil : "title=#{title.inspect}", + ].compact.join(", ") - return '(Classification: ' + data.join(', ') + ')' + return "(Classification: #{field_info})" end def to_s inspect end - protected + private + def reading_to_sort_order(reading_order) sort_order = reading_order diff --git a/app/cover.rb b/app/cover.rb index e74c27b..e3dbad4 100644 --- a/app/cover.rb +++ b/app/cover.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Cover attr_reader :path @@ -13,19 +14,13 @@ class Cover end def inspect - info = [] - if nil != @data - info.push('size=' + @data.length.to_s) - else - info.push('empty') - end - if nil != @path - info.push('path="' + @path + '"') - end - if nil != @mimeType - info.push('mimeType="' + @mimeType + '"') - end - return '(Cover:' + info.join(',') + ')' + field_info = [ + @data.nil? ? nil : "size=#{@data.length.to_s}", + @path.nil? ? nil : "path=#{@path.inspect}", + @mimeType.nil? ? nil : "mime_type=#{@mimeType.inspect}", + ].compact.join(" ") + + "(Cover: #{field_info})" end def read_image(filename) @@ -42,16 +37,19 @@ class Cover open(outputDir + '/' + filename, 'wb') do |fd| fd.write(@data) end + return filename, @mimeType end - protected + private + def getExt pos = @path.rindex('.') if nil == pos return '.img' end - return @path.slice(pos, @path.length) + + @path.slice(pos, @path.length) end end diff --git a/app/main.rb b/app/main.rb index e294b4a..1eee8b4 100644 --- a/app/main.rb +++ b/app/main.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'navigator' require_relative 'page' require_relative 'store' diff --git a/app/series.rb b/app/series.rb index 729f0db..8661704 100644 --- a/app/series.rb +++ b/app/series.rb @@ -1,5 +1,13 @@ class Series + attr_reader :id + + attr_accessor :age + attr_accessor :code + attr_accessor :descr + attr_accessor :genre + attr_accessor :grouping + def initialize(id) @age = nil @genre = nil @@ -9,79 +17,28 @@ class Series @id = id end - def age - @age - end - - def age=(value) - @age = value - end - - def code - @code - end - - def code=(value) - @code = value - end - - def descr - @descr - end - - def descr=(value) - @descr = value - end - - def genre - @genre - end - - def genre=(value) - @genre = value - end - - def grouping - @grouping - end - - def grouping=(value) - @grouping = value - end - - def id - @id - end - def inspect - data = [] - if nil != @age - data.push('age=' + @age.inspect) - end - if nil != @code - data.push('code=' + @code.inspect) - end - if nil != @descr - data.push('descr="' + @descr + '"') - end - if nil != @genre - data.push('genre="' + @genre + '"') - end - if nil != @grouping - data.push('grouping="' + @grouping + '"') - end - return '(Series: ' + data.join(' ') + ')' + field_info = [ + age.nil? ? nil : "age=#{age.inspect}", + code.nil? ? nil : "code=#{code.inspect}", + descr.nil? ? nil : "descr=#{descr.inspect}", + genre.nil? ? nil : "genre=#{genre.inspect}", + grouping.nil? ? nil : "grouping=#{grouping.inspect}", + ].compact.join(" ") + + "(Series: #{field_info})" end def key if nil != grouping and nil != code return grouping.to_s + '_' + code.to_s end - return id.to_s + + id.to_s end def to_s - return inspect() + inspect end end diff --git a/app/store.rb b/app/store.rb index 843d01b..d9257a4 100644 --- a/app/store.rb +++ b/app/store.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'csv' require 'fileutils' @@ -49,11 +50,9 @@ class Store end def cross_reference_lists -puts "@@@@@@@@@@@ CROSS-REF START @@@@@@@@@@@" exec_update("TRUNCATE TABLE Lists CASCADE;", []) populate_lists_table -puts "@@@@@@@@@@@ CROSS-REF DONE @@@@@@@@@@@" end def create_schema(skip_class)