Class: TChart::SettingsParser
- Inherits:
-
Object
- Object
- TChart::SettingsParser
- Defined in:
- lib/tchart/process/settings_parser.rb
Overview
Responsible for parsing a line of source data that contains a setting. Also responsible for accumulating parsed settings.
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
The accumulated settings.
Instance Method Summary collapse
-
#initialize ⇒ SettingsParser
constructor
A new instance of SettingsParser.
-
#parse?(line) ⇒ Boolean
Return true if the passed line is a recognizable settings line (which may nonetheless have errors, such as unknown setting, etc.), false otherwise.
Constructor Details
#initialize ⇒ SettingsParser
Returns a new instance of SettingsParser.
17 18 19 |
# File 'lib/tchart/process/settings_parser.rb', line 17 def initialize @settings = Settings.new end |
Instance Attribute Details
#settings ⇒ Object (readonly)
The accumulated settings. All settings start with their default values and get updated as setting lines are parsed. If a setting is specified more than once in the source data, the last value found will be the one used.
15 16 17 |
# File 'lib/tchart/process/settings_parser.rb', line 15 def settings @settings end |
Instance Method Details
#parse?(line) ⇒ Boolean
Return true if the passed line is a recognizable settings line (which may nonetheless have errors, such as unknown setting, etc.), false otherwise.
26 27 28 29 30 31 32 33 |
# File 'lib/tchart/process/settings_parser.rb', line 26 def parse?(line) return false if (match = /^([^=]+)=(.+)$/.match(line)).nil? name, value_as_string = match[1].strip, match[2].strip raise_unknown_setting(name) unless known_setting?(name) raise_not_a_recognizable_value(value_as_string) unless recognizable_value?(value_as_string) save_setting(name, value_as_string) true end |