module PubliSci::Readers::Output

Public Instance Methods

output(string, options={},append=false) click to toggle source
# File lib/publisci/output.rb, line 4
def output(string, options={},append=false)
  options[:type] = [:string] unless options[:type]
  base = options[:file_base]
  name = options[:file_name]
  types = Array(options[:type])

  if types.include? :print
    puts string
  end

  if types.include? :file
    raise "no file specified output" unless name

    method = append ? 'a' : 'w'
    open("#{base}#{name}", method) { |f| f.write str }
  end

  if types.include? :string
    string
  end
end