Module: Oat::FileHandling

Included in:
OA
Defined in:
lib/oat/support/filehandling.rb

Instance Method Summary collapse

Instance Method Details

#read_oa_dataObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oat/support/filehandling.rb', line 14

def read_oa_data
  # read in OA data
  begin
    @data = File.read(@sourcefile)
  rescue
    raise 'oa_templater_exception'
  end

  begin
    # convert detected encoding (usually SHIFT_JIS Japanese) to UTF-8
    detection = CharlockHolmes::EncodingDetector.detect(@data)
    @data = CharlockHolmes::Converter.convert @data, detection[:encoding], 'UTF-8' unless detection[:encoding] == 'UTF-8'
    @data.gsub!("\r\n", "\n") 
  rescue
    raise 'oa_templater_exception'
  end
end

#read_partial_templatable_file(r = File.join(Oat.txt_dir, 'partial-templates.yml')) ⇒ Object


10
11
12
# File 'lib/oat/support/filehandling.rb', line 10

def read_partial_templatable_file(r = File.join(Oat.txt_dir, 'partial-templates.yml'))
  Oat.configuration.partial_templates = YAML.load_file(r)
end

#read_templatable_file(r = File.join(Oat.txt_dir, 'templatable.yml')) ⇒ Object

A bunch of set phrases that can be swapped out


6
7
8
# File 'lib/oat/support/filehandling.rb', line 6

def read_templatable_file(r = File.join(Oat.txt_dir, 'templatable.yml'))
  Oat.configuration.templatables = YAML.load_file(r)
end