Class: EcoDataFileParser
- Inherits:
-
Object
- Object
- EcoDataFileParser
- Defined in:
- lib/eco_classifier/eco_data_file_parser.rb
Overview
Parses the scid.eco data file into openings
Constant Summary collapse
- ROW_SCANNER =
/\A(?<eco>[A-E]\d{2}[a-z]?)\s+"(?<name>.*)"\s+(?<pgn>.*)\z/
Instance Attribute Summary collapse
-
#openings ⇒ Object
Returns the value of attribute openings.
Instance Method Summary collapse
-
#initialize(eco_file) ⇒ EcoDataFileParser
constructor
A new instance of EcoDataFileParser.
- #scan_into_openings ⇒ Object
Constructor Details
#initialize(eco_file) ⇒ EcoDataFileParser
Returns a new instance of EcoDataFileParser.
8 9 10 11 12 |
# File 'lib/eco_classifier/eco_data_file_parser.rb', line 8 def initialize(eco_file) @text = open(eco_file, 'r').read.strip @text = @text.gsub(/\n /, ' ') @openings = [] end |
Instance Attribute Details
#openings ⇒ Object
Returns the value of attribute openings.
6 7 8 |
# File 'lib/eco_classifier/eco_data_file_parser.rb', line 6 def openings @openings end |
Instance Method Details
#scan_into_openings ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/eco_classifier/eco_data_file_parser.rb', line 14 def scan_into_openings @text.split(/\n/).each do |row| match = row.match(ROW_SCANNER) next unless match @openings << Opening.new(match) end @openings end |