Class: Namelab::CLI::Commands::Generate

Inherits:
Dry::CLI::Command
  • Object
show all
Extended by:
InheritanceHook
Defined in:
lib/namelab/cli.rb

Direct Known Subclasses

Say

Instance Method Summary collapse

Methods included from InheritanceHook

inherited

Instance Method Details

#call(samples:, lengths: [], **opts) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/namelab/cli.rb', line 40

def call(samples:, lengths: [], **opts)
  generators = lengths.each_with_object(opts).map(&WordGenerator)

  samples.to_i.times do
    outputing { generators.map(&:call).join(" ") }
  end
end

#output(result) ⇒ Object



55
56
57
# File 'lib/namelab/cli.rb', line 55

def output(result)
  puts result
end

#outputingObject

Yields the block and outputs result.



49
50
51
52
53
# File 'lib/namelab/cli.rb', line 49

def outputing # :yields:
  result = yield
  fail "Empty result" unless result && result.size > 0
  output(result)
end