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.
Class Method Summary collapse
- .get_description(record) ⇒ Object
- .get_print_synonyms(record) ⇒ Object
-
.get_synonyms(record) ⇒ Object
XXX: delete everything below?.
- .get_term(record) ⇒ Object
- .get_tree(record) ⇒ Object
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.
7 8 9 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 7 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
5 6 7 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 5 def file @file end |
Class Method Details
.get_description(record) ⇒ Object
50 51 52 53 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 50 def self.get_description(record) return [] if record['MS'].blank? record['MS'] end |
.get_print_synonyms(record) ⇒ Object
45 46 47 48 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 45 def self.get_print_synonyms(record) return [] if record['PRINT ENTRY'].blank? record['PRINT ENTRY'].map { |synonym| synonym.split('|').first } end |
.get_synonyms(record) ⇒ Object
XXX: delete everything below?
40 41 42 43 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 40 def self.get_synonyms(record) return [] if record['ENTRY'].blank? record['ENTRY'].map { |synonym| synonym.split('|').first } end |
.get_term(record) ⇒ Object
60 61 62 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 60 def self.get_term(record) record['MH'].first end |
.get_tree(record) ⇒ Object
55 56 57 58 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 55 def self.get_tree(record) return [] if record['MN'].blank? record['MN'] end |
Instance Method Details
#all_records ⇒ Object
32 33 34 35 36 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 32 def all_records result = [] self.each_mesh_record {|rec| result << rec } return result end |
#each_mesh_record {|current_data| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/qa/authorities/mesh_tools/mesh_data_parser.rb', line 11 def each_mesh_record(&block) current_data = {} in_record = false self.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 |