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


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