class ReVIEW::VolumePrinter

Public Class Methods

execute(*args) click to toggle source
# File lib/review/volumeprinter.rb, line 19
def self.execute(*args)
  new.execute(*args)
end
new() click to toggle source
# File lib/review/volumeprinter.rb, line 23
def initialize
  @logger = ReVIEW.logger
  @yamlfile = 'config.yml'
end

Public Instance Methods

execute(*args) click to toggle source
# File lib/review/volumeprinter.rb, line 28
def execute(*args)
  parse_options(args)
  begin
    @config = ReVIEW::Configure.create(yamlfile: @yamlfile)
    @book = ReVIEW::Book::Base.new('.', config: @config)
    unless File.readable?(@yamlfile)
      raise ReVIEW::FileNotFound, "No such fiile or can't open #{@yamlfile}."
    end

    I18n.setup(@book.config['language'])

    @book.each_part do |part|
      if part.number
        print_chapter_volume(part)
      end
      part.each_chapter do |chap|
        print_chapter_volume(chap)
      end
    end
  rescue ReVIEW::ConfigError, ReVIEW::FileNotFound, ReVIEW::CompileError, ReVIEW::ApplicationError => e
    @logger.error e.message
    exit 1
  end
  puts '============================='
  print_volume(@book.volume)
end
parse_options(args) click to toggle source
# File lib/review/volumeprinter.rb, line 55
def parse_options(args)
  opts = OptionParser.new
  opts.version = ReVIEW::VERSION
  opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| @yamlfile = yaml }
  opts.on('--help', 'Print this message and quit') do
    puts opts.help
    exit 0
  end
  begin
    opts.parse!(args)
  rescue OptionParser::ParseError => e
    @logger.error e.message
    $stderr.puts opts.help
    exit 1
  end
end
print_chapter_volume(chap) click to toggle source
print_volume(vol) click to toggle source