Class: Lf::Option

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/lf/option.rb

Constant Summary collapse

SUPPORTED_FORMATS =
Lf::Formatter::FORMATTERS.keys

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = []

  configure_options
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



24
25
26
# File 'lib/lf/option.rb', line 24

def argv
  @argv
end

#filtersObject (readonly)

Returns the value of attribute filters.



24
25
26
# File 'lib/lf/option.rb', line 24

def filters
  @filters
end

#inputObject (readonly)

Returns the value of attribute input.



24
25
26
# File 'lib/lf/option.rb', line 24

def input
  @input
end

#outputObject (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


30
31
32
# File 'lib/lf/option.rb', line 30

def banner
  '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_helpObject



34
35
36
37
# File 'lib/lf/option.rb', line 34

def show_help
  output.puts self
  exit 1
end

#versionObject



26
27
28
# File 'lib/lf/option.rb', line 26

def version
  Lf::VERSION
end