Class: Tables::TableReader
- Inherits:
-
Object
- Object
- Tables::TableReader
- Defined in:
- lib/tables/table_reader.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
-
#extract_all_tables(idx_array = [*0..(table_count-1)]) ⇒ Object
table_count is defined by the concrete class.
- #get_tables ⇒ Object
-
#initialize ⇒ TableReader
constructor
A new instance of TableReader.
- #merge_tables ⇒ Object
Constructor Details
#initialize ⇒ TableReader
Returns a new instance of TableReader.
13 14 15 |
# File 'lib/tables/table_reader.rb', line 13 def initialize @tables=[] end |
Instance Attribute Details
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
11 12 13 |
# File 'lib/tables/table_reader.rb', line 11 def tables @tables end |
Instance Method Details
#extract_all_tables(idx_array = [*0..(table_count-1)]) ⇒ Object
table_count is defined by the concrete class
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tables/table_reader.rb', line 41 def extract_all_tables(idx_array=[*0..(table_count-1)]) # table_count is defined by the concrete class idx_array.each do |idx| table = extract_table(idx) unless table.nil? then status = ">> Extracted table '#{table.name}'" sig=">> signature - #{table.signature}" if block_given? then match=yield(table) if match then @tables << table else status += " - (filtered out)" end else @tables << table end puts status puts sig end end end |
#get_tables ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/tables/table_reader.rb', line 17 def get_tables result=[] if block_given? then @tables.each {|t| result<<t if yield(t)} else result=@tables.clone end result end |
#merge_tables ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tables/table_reader.rb', line 27 def merge_tables sortmerge={} @tables.each do |t| key=t.header if sortmerge.has_key?(key) then sortmerge[key].merge!(t) else sortmerge[key]=t end end @tables=[] sortmerge.values.each {|v| @tables << v} end |