Class: TChart::ItemsParser

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

Overview

Responsible for parsing a line of source data that contains either a separator or a data item. Also responsible for accumulating parsed items.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeItemsParser

Returns a new instance of ItemsParser.



19
20
21
# File 'lib/tchart/process/items_parser.rb', line 19

def initialize
  @items = []
end

Instance Attribute Details

#itemsObject (readonly)

The collection of parsed items, where an item is either an instance of YItem or of Separator. Starts empty and fills up with each successive call to #parse.



17
18
19
# File 'lib/tchart/process/items_parser.rb', line 17

def items
  @items
end

Instance Method Details

#parse(line) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/tchart/process/items_parser.rb', line 23

def parse(line)
  description, style, *date_range_strings = extract_fields(line)
  raise_description_missing if description.nil?
  raise_style_missing if style.nil? && date_range_strings.length > 0
  if description.start_with?("---")
    parse_separator
  else
    parse_y_item(description, style, date_range_strings)
  end
end