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



28
29
30
31
32
# File 'lib/codeless_code/commands/filter_fables.rb', line 28

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/codeless_code/commands/filter_fables.rb', line 24

def options
  @options
end

Instance Method Details

#call(&blk) ⇒ Object



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

def call(&blk)
  fables = filters_from_options(&blk)

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