Class: Qa::Authorities::MeshTools::MeshDataParser
- Inherits:
-
Object
- Object
- Qa::Authorities::MeshTools::MeshDataParser
- Defined in:
- lib/qa/authorities/mesh_tools/mesh_data_parser.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #all_records ⇒ Object
- #each_mesh_record {|current_data| ... } ⇒ Object
-
#initialize(file) ⇒ MeshDataParser
constructor
A new instance of MeshDataParser.
Constructor Details
#initialize(file) ⇒ MeshDataParser
Returns a new instance of MeshDataParser.
6 7 8 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 6 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 4 def file @file end |
Instance Method Details
#all_records ⇒ Object
31 32 33 34 35 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 31 def all_records result = [] each_mesh_record { |rec| result << rec } result end |
#each_mesh_record {|current_data| ... } ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 10 def each_mesh_record current_data = {} in_record = false file.each_line do |line| case line when /\A\*NEWRECORD/ yield(current_data) if in_record in_record = true current_data = {} when /\A(?<term>[^=]+) = (?<value>.*)/ current_data[Regexp.last_match(:term)] ||= [] current_data[Regexp.last_match(:term)] << Regexp.last_match(:value).strip when /\A\n/ yield(current_data) if in_record in_record = false end end # final time in case file did not end with a blank line yield(current_data) if in_record end |