Method: Fech::Filing#fix_f99_contents

Defined in:
lib/fech/filing.rb

#fix_f99_contentsObject

Handle the contents of F99s by removing the

BEGINTEXT

and [ENDTEXT] delimiters and

putting the text content onto the same line as the summary.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/fech/filing.rb', line 279

def fix_f99_contents
  @customized = true
  content = file_contents.read
  
  if RUBY_VERSION > "1.9.2"
    content.encode!('UTF-16', 'UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
    content.encode!('UTF-8', 'UTF-16')
  else
    require 'iconv'
    ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') 
    content = ic.iconv(content + ' ')[0..-2] # add valid byte before converting, then remove it
  end
  
  regex = /\n\[BEGINTEXT\]\n(.*?)\[ENDTEXT\]\n/mi # some use eg [EndText]
  match = content.match(regex)
  if match
    repl = match[1].gsub(/"/, '""')
    content.gsub(regex, "#{delimiter}\"#{repl}\"")
  else
    content
  end
end