Class: HTMLFilter::CLI
- Inherits:
-
Object
- Object
- HTMLFilter::CLI
- Defined in:
- lib/htmlfilter.rb
Overview
Simple Command line interface for HTMLFilter.
It can be configured via a YAML file.
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parser ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
663 664 665 666 667 |
# File 'lib/htmlfilter.rb', line 663 def initialize require 'optparse' @config_file = nil @options = {} end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
659 660 661 |
# File 'lib/htmlfilter.rb', line 659 def config_file @config_file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
661 662 663 |
# File 'lib/htmlfilter.rb', line 661 def @options end |
Class Method Details
.run ⇒ Object
655 656 657 |
# File 'lib/htmlfilter.rb', line 655 def self.run new.run end |
Instance Method Details
#parser ⇒ Object
669 670 671 672 673 674 |
# File 'lib/htmlfilter.rb', line 669 def parser OptionParser.new do |opt| opt.on('--config <YAML_FILE>', 'filter with custom configuration'){ |file| @config_file = file } opt.on('--debug', 'run in debug mode to see error details'){ $DEBUG = true } end end |
#run ⇒ Object
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/htmlfilter.rb', line 683 def run parser.parse! begin files = ARGV files.each do |f| raise "htmlfilter: file not found -- #{f}" unless File.exist?(f) end files.each do |file| html = File.read(file) puts HTMLFilter.new().filter(html) end rescue => error raise error if $DEBUG $stderr.puts error end end |