Module: CfScript::Output::Parser::Table
- Included in:
- CfScript::Output::Parser
- Defined in:
- lib/cf_script/output/parser/table.rb
Instance Method Summary collapse
- #parse_columns(line) ⇒ Object
- #parse_row(line, columns) ⇒ Object
- #parse_rows(lines) ⇒ Object
- #parse_table(buffer, headers) ⇒ Object
Instance Method Details
#parse_columns(line) ⇒ Object
3 4 5 |
# File 'lib/cf_script/output/parser/table.rb', line 3 def parse_columns(line) line ? line.split(/\s{2,}/).map(&:strip) : [] end |
#parse_row(line, columns) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cf_script/output/parser/table.rb', line 7 def parse_row(line, columns) row = CfScript::AttributeList.new values = line.split(/\s{2,}/, columns.length).map!(&:strip) columns.each_with_index do |column, index| # Special case for instance status tables name = index == 0 && column == '' ? 'index' : column row << CfScript::Attribute.new( symbolize(name), (values[index] ? values[index].strip : '') ) end row end |
#parse_rows(lines) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cf_script/output/parser/table.rb', line 24 def parse_rows(lines) rows = [] if lines.first.strip.empty? lines.shift end cols = parse_columns(lines.shift) lines.each do |line| rows << parse_row(line, cols) end rows end |
#parse_table(buffer, headers) ⇒ Object
40 41 42 43 44 |
# File 'lib/cf_script/output/parser/table.rb', line 40 def parse_table(buffer, headers) if m = buffer.match(/^#{headers.join('\s+')}/) parse_rows buffer[m.begin(0)..-1].lines end end |