Class: ReVIEW::VolumePrinter
Class Method Summary collapse
Instance Method Summary collapse
- #execute(*args) ⇒ Object
-
#initialize ⇒ VolumePrinter
constructor
A new instance of VolumePrinter.
- #parse_options(args) ⇒ Object
- #print_chapter_volume(chap) ⇒ Object
- #print_volume(vol) ⇒ Object
Constructor Details
Class Method Details
.execute(*args) ⇒ Object
19 20 21 |
# File 'lib/review/volumeprinter.rb', line 19 def self.execute(*args) new.execute(*args) end |
Instance Method Details
#execute(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/review/volumeprinter.rb', line 29 def execute(*args) (args) @book = ReVIEW::Book::Base.load @book.config = @config unless File.readable?(@yamlfile) @logger.error("No such fiile or can't open #{@yamlfile}.") exit 1 end @book.load_config(@yamlfile) I18n.setup(@book.config['language']) begin @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::FileNotFound => e @logger.error e exit 1 end puts '=============================' print_volume(@book.volume) end |
#parse_options(args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/review/volumeprinter.rb', line 57 def (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. $stderr.puts opts.help exit 1 end end |
#print_chapter_volume(chap) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/review/volumeprinter.rb', line 74 def print_chapter_volume(chap) builder = ReVIEW::PLAINTEXTBuilder.new builder.bind(ReVIEW::Compiler.new(builder), chap, nil) vol = chap.volume title = chap.format_number unless title.empty? title += ' ' end begin title += builder.compile_inline(chap.title) rescue ReVIEW::ApplicationError => e @logger.warn "#{chap.name} : #{e..sub(/.+error: /, '')}" end printf("%3dKB %6dC %5dL %3dP %s %-s\n", vol.kbytes, vol.chars, vol.lines, vol.page, "#{chap.name} ".ljust(15, '.'), title) end |
#print_volume(vol) ⇒ Object
94 95 96 97 |
# File 'lib/review/volumeprinter.rb', line 94 def print_volume(vol) # total printf("%3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page) end |