Class: Lf::Option
- Inherits:
-
OptionParser
- Object
- OptionParser
- Lf::Option
- Defined in:
- lib/lf/option.rb
Constant Summary collapse
- SUPPORTED_FORMATS =
Lf::Formatter::FORMATTERS.keys
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #banner ⇒ Object
-
#initialize(argv, stdin, stdout) ⇒ Option
constructor
A new instance of Option.
- #parse! ⇒ Object
- #show_help ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(argv, stdin, stdout) ⇒ Option
Returns a new instance of Option.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lf/option.rb', line 13 def initialize(argv, stdin, stdout) super() @argv, @input, @output = argv.dup, stdin, stdout @options = { format: 'ltsv' } @filters = [] end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
24 25 26 |
# File 'lib/lf/option.rb', line 24 def argv @argv end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
24 25 26 |
# File 'lib/lf/option.rb', line 24 def filters @filters end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
24 25 26 |
# File 'lib/lf/option.rb', line 24 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
24 25 26 |
# File 'lib/lf/option.rb', line 24 def output @output end |
Class Method Details
.parse(*args) ⇒ Object
9 10 11 |
# File 'lib/lf/option.rb', line 9 def self.parse(*args) new(*args).tap { |option| option.parse!(option.argv) } end |
Instance Method Details
#[](key) ⇒ Object
46 47 48 |
# File 'lib/lf/option.rb', line 46 def [](key) @options[key] end |
#banner ⇒ Object
30 31 32 |
# File 'lib/lf/option.rb', line 30 def 'Usage: lf [options] <filters ...> [file]' end |
#parse! ⇒ Object
39 40 41 42 43 44 |
# File 'lib/lf/option.rb', line 39 def parse!(*) super @input = open(@argv.pop, 'r') if File.file?(@argv.last.to_s) @filters = Lf::Filter.parse(@argv) end |
#show_help ⇒ Object
34 35 36 37 |
# File 'lib/lf/option.rb', line 34 def show_help output.puts self exit 1 end |