Class: Bismas::CLI::Filter

Inherits:
Bismas::CLI show all
Defined in:
lib/bismas/cli/filter.rb

Constant Summary collapse

TYPES =
%w[dat dbm]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bismas::CLI

#execute_options, #input_options, #require_gem, #type_option, #unsupported_type

Class Method Details

.defaultsObject



35
36
37
38
39
40
# File 'lib/bismas/cli/filter.rb', line 35

def self.defaults
  super.merge(
    type:       TYPES.first,
    key_format: '%s'
  )
end

Instance Method Details

#run(arguments) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bismas/cli/filter.rb', line 42

def run(arguments)
  quit unless arguments.empty?

  klass = case type = options[:type]
    when 'dat'
      Writer
    when 'dbm'
      require_gem 'midos'
      options[:output_encoding] ||= Midos::DEFAULT_ENCODING
      Midos::Writer
    else
      unsupported_type(type)
  end

  Bismas.filter(klass, options, &method(:quit))
end