Class: TChart::DataParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tchart/process/data_parser.rb

Overview

Responsible for parsing source data. Not responsible for aquiring the source data, e.g. not responsible for reading the source data from an input file.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_name, source_data) ⇒ DataParser

Returns a new instance of DataParser.



19
20
21
22
23
24
25
26
# File 'lib/tchart/process/data_parser.rb', line 19

def initialize(source_name, source_data)
  @source_name = source_name
  @source_data = source_data
  @line_number = nil
  @errors = []
  @settings_parser = SettingsParser.new
  @items_parser = ItemsParser.new
end

Class Method Details

.parse(source_name, source_data) ⇒ Object

source_name is used in error messages; for example, if the source data was read from a file, then source_name would be the name of that file.



15
16
17
# File 'lib/tchart/process/data_parser.rb', line 15

def self.parse(source_name, source_data) # => [ settings, items, errors ]
  DataParser.new(source_name, source_data).parse
end

Instance Method Details

#parseObject

> [ settings, items, errors ]



28
29
30
31
32
# File 'lib/tchart/process/data_parser.rb', line 28

def parse # => [ settings, items, errors ]
  non_blank_source_lines.each { |line| parse_line(line) }
  check_for_items if @errors.empty?
  [ @settings_parser.settings, @items_parser.items, @errors ]
end