Class: Fleetctl::TableParser
- Inherits:
-
Object
- Object
- Fleetctl::TableParser
- Defined in:
- lib/fleetctl/table_parser.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw) ⇒ TableParser
constructor
A new instance of TableParser.
- #parse ⇒ Object
Constructor Details
#initialize(raw) ⇒ TableParser
Returns a new instance of TableParser.
11 12 13 |
# File 'lib/fleetctl/table_parser.rb', line 11 def initialize(raw) @raw = raw end |
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
3 4 5 |
# File 'lib/fleetctl/table_parser.rb', line 3 def raw @raw end |
Class Method Details
.parse(raw) ⇒ Object
6 7 8 |
# File 'lib/fleetctl/table_parser.rb', line 6 def parse(raw) self.new(raw).parse end |
Instance Method Details
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fleetctl/table_parser.rb', line 15 def parse rows = raw.split("\n").map { |row| row.split(/\t+/) } header = rows.shift if header keys = header.map { |key| key.downcase.to_sym } [].tap do |output| rows.each do |row| scrubbed_row = row.map { |val| val == '-' ? nil : val } output << Hash[keys.zip(scrubbed_row)] end end else Fleetctl.logger.error('ERROR in Fleetctl::TableParser.parse - no header row found') [] end end |