Class: CodelessCode::Commands::FilterFables

Inherits:
Object
  • Object
show all
Defined in:
lib/codeless_code/commands/filter_fables.rb

Overview

Filters down a CodelessCode::Catalog of Fables with criteria specified via the CLI. The results will be listed line-by-line, unless only one fable is found. In that case, it will be printed out.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(catalog, options, io: nil) ⇒ FilterFables

Returns a new instance of FilterFables.

Parameters:

  • io (IO) (defaults to: nil)

    if given, the output will be written to this stream, otherwise we will attempt to invoke the user’s PAGER app



26
27
28
29
30
# File 'lib/codeless_code/commands/filter_fables.rb', line 26

def initialize(catalog, options, io: nil)
  @catalog = catalog
  @options = options
  @io = io
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/codeless_code/commands/filter_fables.rb', line 22

def options
  @options
end

Instance Method Details

#callObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/codeless_code/commands/filter_fables.rb', line 32

def call
  filter = Filters::FromOptions.new(options)
  fables = @catalog.select(filter)
  fables = yield fables if block_given?
  fables = sort(fables)

  case fables.size
  when 0
    warn 'None found.'
  when 1
    show(fables.first)
  else
    list(fables)
  end
end