class BioTable::LazyValues

LazyValues fetches values on demand from the @fields array. In the [] method a field is transformed into a float when it is called.

Public Class Methods

new(fields) click to toggle source
# File lib/bio-table/filter.rb, line 10
def initialize fields
  @fields = fields
  @values = []  # cache values
end

Public Instance Methods

[](index) click to toggle source
# File lib/bio-table/filter.rb, line 15
def [] index
  if not @values[index]
    field = @fields[index]
    @values[index] = (Filter::valid_number?(field) ? field.to_f : nil )
  end
  @values[index].freeze
  @values[index]
end
compact() click to toggle source
# File lib/bio-table/filter.rb, line 34
def compact
  a = []
  each do | e |
    a << e if e != nil
  end
  a
end
each() { |self| ... } click to toggle source
# File lib/bio-table/filter.rb, line 24
def each &block
  @fields.each_with_index do |field,i|
    if block_given?
      block.call self[i]
    else
      yield self[i]
    end
  end
end
size() click to toggle source
# File lib/bio-table/filter.rb, line 42
def size
  @fields.size
end