From 323c2519e198389f30c35e491aeb12145d907887 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 16 Aug 2020 22:21:41 +0900 Subject: [PATCH] add BookUnit class instead of Compilable module `BookUnit` is (abstract) superclass of `Chapter` and `Part`. --- lib/review/book/{compilable.rb => book_unit.rb} | 8 +++++++- lib/review/book/chapter.rb | 10 +++------- lib/review/book/part.rb | 10 +++------- 3 files changed, 13 insertions(+), 15 deletions(-) rename lib/review/book/{compilable.rb => book_unit.rb} (96%) diff --git a/lib/review/book/compilable.rb b/lib/review/book/book_unit.rb similarity index 96% rename from lib/review/book/compilable.rb rename to lib/review/book/book_unit.rb index 16b4ed5b8..8e3e0e514 100644 --- a/lib/review/book/compilable.rb +++ b/lib/review/book/book_unit.rb @@ -10,12 +10,18 @@ module ReVIEW module Book - module Compilable + class BookUnit include TextUtils attr_reader :book attr_reader :path attr_accessor :content + def initialize(book, number, name = nil) + @book = book + @number = number + @name = name + end + def dirname return nil unless @path File.dirname(@path) diff --git a/lib/review/book/chapter.rb b/lib/review/book/chapter.rb index 789b3e1b1..e69be5931 100644 --- a/lib/review/book/chapter.rb +++ b/lib/review/book/chapter.rb @@ -7,15 +7,13 @@ # the GNU LGPL, Lesser General Public License version 2.1. # For details of the GNU LGPL, see the file "COPYING". # -require 'review/book/compilable' +require 'review/book/book_unit' require 'review/lineinput' require 'review/preprocessor' module ReVIEW module Book - class Chapter - include Compilable - + class Chapter < BookUnit attr_reader :number, :book def self.mkchap(book, name, number = nil) @@ -34,9 +32,7 @@ def self.mkchap_ifexist(book, name, number = nil) end def initialize(book, number, name, path, io = nil) - @book = book - @number = number - @name = name + super(book, number, name) @path = path @io = io @title = nil diff --git a/lib/review/book/part.rb b/lib/review/book/part.rb index e540452cd..9db04455a 100644 --- a/lib/review/book/part.rb +++ b/lib/review/book/part.rb @@ -6,13 +6,11 @@ # the GNU LGPL, Lesser General Public License version 2.1. # For details of the GNU LGPL, see the file "COPYING". # -require 'review/book/compilable' +require 'review/book/book_unit' module ReVIEW module Book - class Part - include Compilable - + class Part < BookUnit def self.mkpart_from_namelistfile(book, path) chaps = [] File.read(path, mode: 'rt:BOM|utf-8').split.each_with_index do |name, number| @@ -36,10 +34,8 @@ def self.mkpart(chaps) # if Part is dummy, `number` is nil. # def initialize(book, number, chapters, name = '', io = nil) - @book = book - @number = number + super(book, number, name) @chapters = chapters - @name = name @path = name @content = '' if io