Class: BioTable::LazyValues
- Inherits:
-
Object
- Object
- BioTable::LazyValues
- Includes:
- Enumerable
- Defined in:
- lib/bio-table/filter.rb
Overview
LazyValues fetches values on demand from the @fields array. In the [] method a field is transformed into a float when it is called.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #compact ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(fields) ⇒ LazyValues
constructor
A new instance of LazyValues.
- #size ⇒ Object
Constructor Details
#initialize(fields) ⇒ LazyValues
Returns a new instance of LazyValues.
10 11 12 13 |
# File 'lib/bio-table/filter.rb', line 10 def initialize fields @fields = fields @values = [] # cache values end |
Instance Method Details
#[](index) ⇒ Object
15 16 17 18 19 20 21 22 |
# 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 ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/bio-table/filter.rb', line 34 def compact a = [] each do | e | a << e if e != nil end a end |
#each(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
42 43 44 |
# File 'lib/bio-table/filter.rb', line 42 def size @fields.size end |