Class: Crucigrama::CLI::Print
- Inherits:
-
Object
- Object
- Crucigrama::CLI::Print
- Defined in:
- lib/crucigrama/cli/print.rb
Instance Method Summary collapse
- #extract_options(*args) ⇒ Object
-
#initialize(*args) ⇒ Print
constructor
A new instance of Print.
- #options_parser ⇒ Object
Constructor Details
#initialize(*args) ⇒ Print
Returns a new instance of Print.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/crucigrama/cli/print.rb', line 49 def initialize(*args) (*args) crossword = begin Crucigrama::Crossword.new(MultiJson.decode([:json_crossword])) rescue Exception => exc STDERR.puts exc. STDERR.puts "Could not parse input crossword!" exit 1 end begin crossword.to_pdf([:output_file], :include_solution => [:include_solution]) rescue Exception => exc STDERR.puts exc. STDERR.puts "Could not print crossword!" exit 1 end end |
Instance Method Details
#extract_options(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/crucigrama/cli/print.rb', line 36 def (*args) @options = {} .parse!(args) unless [:json_crossword] STDERR.puts "Must specify input file!" exit 1 end unless [:output_file] STDERR.puts "Must specify output file!" exit 1 end end |
#options_parser ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/crucigrama/cli/print.rb', line 6 def @options_parser ||= OptionParser.new do |opts| opts. = "Usage: #{Crucigrama::CLI.cli_command} print options" opts.separator "" opts.separator "Options:" opts.on("-o", "--output PDF_FILE", "Prints the crossword to PDF_FILE") do |file| @options[:output_file] = file end opts.on("-i", "--input JSON_FILE", "Extracts the crossword from the JSON_FILE file") do |file| begin @options[:json_crossword] = File.read(file) rescue Exception => exc STDERR.puts exc. end end opts.on("--[no-]solution", "Prints a reduced and inverted solution for the crossword next to it") do |value| @options[:include_solution] = value end opts.separator "" opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do puts Crucigrama::VERSION exit end end end |