Class: Patinfo2csv::Loader
- Inherits:
-
Object
- Object
- Patinfo2csv::Loader
- Defined in:
- lib/patinfo2csv/loader.rb
Instance Method Summary collapse
- #extract_line(line) ⇒ Object
-
#initialize ⇒ Loader
constructor
A new instance of Loader.
- #load_yaml(patinfo_yaml) ⇒ Object
Constructor Details
#initialize ⇒ Loader
Returns a new instance of Loader.
6 7 8 |
# File 'lib/patinfo2csv/loader.rb', line 6 def initialize @lines = '' end |
Instance Method Details
#extract_line(line) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/patinfo2csv/loader.rb', line 21 def extract_line(line) case line when /^\s*(start:|end:|name:|preformatted:)\s/, \ /^\s*:article_(pcode|size|dose):/ # NOTE # To make sure that these lines are unused for YAML structure nil when /^\s*(heading:|subheading:|text:)\s/, \ /^\s{12}(?!values:|\-)\w+/ # multi lines text Patinfo2csv::ESCAPED_CHAR_CODE_MAP.each do |code, char| line.gsub!(code, char) end line else line end end |
#load_yaml(patinfo_yaml) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/patinfo2csv/loader.rb', line 9 def load_yaml(patinfo_yaml) # before yaml loading, replace escaped chars File.open(patinfo_yaml, "r:ascii:utf-8") do |f| while line = f.gets if line = extract_line(line) @lines << line end end end fh = StringIO.new(@lines) YAML.load_documents(fh) # force utf-8 end |