class BioDSL::Dump
Dump
records in stream to STDOUT.¶ ↑
dump
outputs records from the stream to STDOUT.
Usage¶ ↑
dump([first: <uint> |last: <uint>])
Options¶ ↑
-
first <uint> - Only dump the first number of records.
-
last <uint> - Only dump the last number of records.
Examples¶ ↑
To dump all records in the stream:
dump
To dump only the first 10 records:
dump(first: 10)
To dump only the last 10 records:
dump(last: 10)
Constants
- STATS
Public Class Methods
Constructor for the Dump
class.
@param [Hash] options Options hash. @option options [Integer] :first Dump
first number of records. @option options [Integer] :last Dump
last number of records.
@return [Dump] Returns an instance of the Dump
class.
# File lib/BioDSL/commands/dump.rb, line 65 def initialize(options) @options = options check_options end
Public Instance Methods
Return a lambda for the dump command.
@return [Proc] Returns the dump command lambda.
# File lib/BioDSL/commands/dump.rb, line 74 def lmb lambda do |input, output, status| status_init(status, STATS) if @options[:first] dump_first(input, output) elsif @options[:last] dump_last(input, output) else dump_all(input, output) end end end
Private Instance Methods
Check the options and return a lambda for the command.
# File lib/BioDSL/commands/dump.rb, line 91 def check_options options_allowed(@options, :first, :last) options_unique(@options, :first, :last) options_assert(@options, ':first > 0') options_assert(@options, ':last > 0') end
Dump
all records.
@param input [Enumerator::Yielder] Input stream. @param output [Enumerator::Yielder] Output stream.
# File lib/BioDSL/commands/dump.rb, line 144 def dump_all(input, output) input.each do |record| @status[:records_in] += 1 puts record if output output << record @status[:records_out] += 1 end end end
Dump
the first number of records.
@param input [Enumerator::Yielder] Input stream. @param output [Enumerator::Yielder] Output stream.
# File lib/BioDSL/commands/dump.rb, line 102 def dump_first(input, output) input.first(@options[:first]).each do |record| @status[:records_in] += 1 puts record if output output << record @status[:records_out] += 1 end end end
Dump
the last number of records.
@param input [Enumerator::Yielder] Input stream. @param output [Enumerator::Yielder] Output stream.
# File lib/BioDSL/commands/dump.rb, line 119 def dump_last(input, output) buffer = [] last = @options[:last] input.each do |record| @status[:records_in] += 1 buffer << record buffer.shift if buffer.size > last end buffer.each do |record| puts record if output output << record @status[:records_out] += 1 end end end