Class: HTMLTable
- Inherits:
-
Object
- Object
- HTMLTable
- Defined in:
- lib/zarchitect/htmltable.rb
Instance Method Summary collapse
- #add_line(l) ⇒ Object
- #ends_at(x) ⇒ Object
-
#initialize ⇒ HTMLTable
constructor
A new instance of HTMLTable.
- #print ⇒ Object
- #process ⇒ Object
- #replace(ar) ⇒ Object
- #starts_at(x) ⇒ Object
Constructor Details
#initialize ⇒ HTMLTable
Returns a new instance of HTMLTable.
3 4 5 6 7 8 9 10 |
# File 'lib/zarchitect/htmltable.rb', line 3 def initialize @lines = Array.new @starts_at = nil @ends_at = nil @coln = 0 @html = "<table>" @rows = Array.new end |
Instance Method Details
#add_line(l) ⇒ Object
39 40 41 42 |
# File 'lib/zarchitect/htmltable.rb', line 39 def add_line(l) @coln = l.count('|') if l.count('|') > @coln @lines.push l end |
#ends_at(x) ⇒ Object
52 53 54 |
# File 'lib/zarchitect/htmltable.rb', line 52 def ends_at(x) @ends_at = x end |
#print ⇒ Object
44 45 46 |
# File 'lib/zarchitect/htmltable.rb', line 44 def print @lines.each { |l| p l } end |
#process ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zarchitect/htmltable.rb', line 12 def process @coln -= 1 # table syntax expects one more pipes than columns @lines.each_with_index do |l,i| ar = l.split('|', -1) ar.shift ar.pop ar2 = get_colspans(ar) ar.map! { |a| a.strip } if ar[0].count("-") == ar[0].length && ar[0].count("-") > 0 # header previous row is header @rows.last.set_header else # row @rows.push HTMLTableRow.new(ar,ar2) end end @rows.each do |r| r.process @html << r.html end @html << "</table>" end |
#replace(ar) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zarchitect/htmltable.rb', line 56 def replace(ar) ar[@starts_at] = @html if @ends_at.nil? @ends_at = ar.length process end ar.each_with_index do |x,i| ar[i] = nil if i > @starts_at && i <= @ends_at end ar end |
#starts_at(x) ⇒ Object
48 49 50 |
# File 'lib/zarchitect/htmltable.rb', line 48 def starts_at(x) @starts_at = x end |