class Bismas::CLI::Filter

Constants

TYPES

Public Class Methods

defaults() click to toggle source
Calls superclass method
   # File lib/bismas/cli/filter.rb
35 def self.defaults
36   super.merge(
37     type:       TYPES.first,
38     key_format: '%s'
39   )
40 end

Public Instance Methods

run(arguments) click to toggle source
   # File lib/bismas/cli/filter.rb
42 def run(arguments)
43   quit unless arguments.empty?
44 
45   klass = case type = options[:type]
46     when 'dat'
47       Writer
48     when 'dbm'
49       require_gem 'midos'
50       options[:output_encoding] ||= Midos::DEFAULT_ENCODING
51       Midos::Writer
52     else
53       unsupported_type(type)
54   end
55 
56   Bismas.filter(klass, options, &method(:quit))
57 end

Private Instance Methods

opts(opts) click to toggle source
    # File lib/bismas/cli/filter.rb
 61 def opts(opts)
 62   opts.summary_width = 34
 63 
 64   opts.option(:input__FILE, 'Path to input file [Default: STDIN]')
 65 
 66   opts.option(:output__FILE, 'Path to output file [Default: STDOUT]')
 67 
 68   input_options(opts)
 69 
 70   opts.separator
 71   opts.separator 'Output options:'
 72 
 73   type_option(opts)
 74 
 75   opts.separator
 76 
 77   opts.option(:output_encoding__ENCODING, :n, 'Output encoding [Default: depends on TYPE]')
 78 
 79   opts.separator
 80 
 81   opts.option(:output_key__KEY, :k, 'ID key of output file')
 82   opts.option(:key_format__KEY_FORMAT, :f, 'Key format [Default: %s]')
 83 
 84   opts.separator
 85 
 86   opts.option(:mapping__FILE_OR_YAML, 'Path to mapping file or YAML string')
 87 
 88   opts.separator
 89 
 90   opts.switch(:sort, 'Sort each record')
 91 
 92   opts.separator
 93 
 94   execute_options(opts)
 95 
 96   opts.separator
 97 
 98   opts.option(:padding_length__LENGTH, :P, Integer, "Length of padding for TYPE=dat [Default: #{DEFAULT_PADDING_LENGTH}]")
 99 
100   opts.separator
101   opts.separator 'Common options:'
102 
103   opts.option(:category_length__LENGTH, :C, Integer, "Length of category for TYPE=dat [Default: #{DEFAULT_CATEGORY_LENGTH}]")
104 end