Sha256: e8fed8ae830d0a51cbad39c1adca7fc4165f86b1b8d4ca58f0633b1233ef227c

Contents?: true

Size: 725 Bytes

Versions: 8

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

#
# Base class of logic class
#
class BaseLogic
  def initialize
    @in  = $stdin
    @out = $stdout
    @err = $stderr
  end

  def source_output(source = $stdout)
    @out = source
  end

  def source_input(source = $stdin)
    @in = source
    if source.nil? || source =~ /^-$/
      # If the file name is "-", use STDIN.
      @in = $stdin
    else
      file(source)
    end
  end

  def source_err(source = $stderr)
    @err = source
  end

  private

  def file(filename)
    @in = File.open(filename)
  rescue SystemCallError => e
    @err.puts e.message.to_s
    # TODO: Define error codes as enum.
    exit(2)
  rescue IOError => e
    @err.puts e.message.to_s
    exit(2)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cureutils-1.7.0 lib/cureutils/logic/base_logic.rb
cureutils-1.6.0 lib/cureutils/logic/base_logic.rb
cureutils-1.5.0 lib/cureutils/logic/base_logic.rb
cureutils-1.4.0 lib/cureutils/logic/base_logic.rb
cureutils-1.3.1 lib/cureutils/logic/base_logic.rb
cureutils-1.3.0 lib/cureutils/logic/base_logic.rb
cureutils-1.2.0 lib/cureutils/logic/base_logic.rb
cureutils-1.1.1 lib/cureutils/logic/base_logic.rb