Class: Html2haml::Exec::Generic
- Inherits:
-
Object
- Object
- Html2haml::Exec::Generic
- Defined in:
- lib/html2haml/exec.rb
Overview
An abstract class that encapsulates the executable code for the Html2haml executable. It's split into a base class and a subclass for historic reasons: this previously was used by all the executables in the Haml project, before Html2haml was moved into its own gem.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(args) ⇒ Generic
constructor
A new instance of Generic.
-
#parse ⇒ Object
Parses the command-line arguments and runs the executable.
-
#parse! ⇒ Object
Parses the command-line arguments and runs the executable.
-
#to_s ⇒ String
A description of the executable.
Constructor Details
#initialize(args) ⇒ Generic
Returns a new instance of Generic.
14 15 16 17 |
# File 'lib/html2haml/exec.rb', line 14 def initialize(args) @args = args @options = {:for_engine => {}} end |
Instance Method Details
#parse ⇒ Object
Parses the command-line arguments and runs the executable. This does not handle exceptions or exit the program.
41 42 43 44 45 46 47 48 |
# File 'lib/html2haml/exec.rb', line 41 def parse @opts = OptionParser.new(&method(:set_opts)) @opts.parse!(@args) process_result @options end |
#parse! ⇒ Object
Parses the command-line arguments and runs the executable.
Calls Kernel#exit
at the end, so it never returns.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/html2haml/exec.rb', line 23 def parse! begin parse rescue Exception => e raise e if @options[:trace] || e.is_a?(SystemExit) $stderr.print "#{e.class}: " unless e.class == RuntimeError $stderr.puts "#{e.}" $stderr.puts " Use --trace for backtrace." exit 1 end exit 0 end |
#to_s ⇒ String
Returns A description of the executable.
51 52 53 |
# File 'lib/html2haml/exec.rb', line 51 def to_s @opts.to_s end |