class Muwu::Destination

Constants

MARGIN

Attributes

margin_current[RW]
output[W]
output_class[RW]
output_filename[RW]
output_working_directory[RW]

Public Class Methods

new() click to toggle source
# File lib/muwu/destination/destination.rb, line 22
def initialize
  @margin_depth = 0
  @output = nil
end

Public Instance Methods

filename() click to toggle source
# File lib/muwu/destination/destination.rb, line 42
def filename
  @output_filename
end
inspect() click to toggle source
# File lib/muwu/destination/destination.rb, line 28
def inspect
  ["#{self.to_s}", "{", inspect_instance_variables, "}"].join(' ')
end
inspect_instance_variables() click to toggle source
# File lib/muwu/destination/destination.rb, line 33
def inspect_instance_variables
  self.instance_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ")
end
margin_dec() click to toggle source
# File lib/muwu/destination/destination.rb, line 47
def margin_dec
  @margin_depth = @margin_depth.to_i - 1
end
margin_inc() click to toggle source
# File lib/muwu/destination/destination.rb, line 52
def margin_inc
  @margin_depth = @margin_depth.to_i + 1
end
margin_indent() { || ... } click to toggle source
# File lib/muwu/destination/destination.rb, line 57
def margin_indent
  margin_inc
  yield
  margin_dec
end
margin_to_zero() click to toggle source
# File lib/muwu/destination/destination.rb, line 64
def margin_to_zero
  @margin_depth = 0
end
output() click to toggle source
# File lib/muwu/destination/destination.rb, line 69
def output
  begin
    if output_is_closed
      raise ProjectExceptionHandler::Fatal.new(ProjectException::OutputNotOpen.new)
    elsif output_is_opened
      @output
    end
  end
end
output_is_closed() click to toggle source
# File lib/muwu/destination/destination.rb, line 80
def output_is_closed
  @output == nil
end
output_is_opened() click to toggle source
# File lib/muwu/destination/destination.rb, line 85
def output_is_opened
  @output != nil
end
output_stream() { || ... } click to toggle source
# File lib/muwu/destination/destination.rb, line 90
def output_stream
  announce_open
  output_open
  yield
  output_close
end
padding_vertical(n) { || ... } click to toggle source
# File lib/muwu/destination/destination.rb, line 98
def padding_vertical(n)
  output.print ("\n" * n)
  yield
  output.print ("\n" * n)
end
write_inline(value) click to toggle source
# File lib/muwu/destination/destination.rb, line 105
def write_inline(value)
  write_value(value)
end
write_inline_end(value) click to toggle source
# File lib/muwu/destination/destination.rb, line 110
def write_inline_end(value)
  write_value(value)
  write_lf
end
write_inline_indented(value) click to toggle source
# File lib/muwu/destination/destination.rb, line 116
def write_inline_indented(value)
  write_margin
  write_value(value)
end
write_lf() click to toggle source
# File lib/muwu/destination/destination.rb, line 122
def write_lf
  output.print "\n"
end
write_line(value) click to toggle source
# File lib/muwu/destination/destination.rb, line 127
def write_line(value)
  write_margin
  write_value(value)
  write_lf
end
write_margin() click to toggle source
# File lib/muwu/destination/destination.rb, line 134
def write_margin
  output.print render_current_margin
end
write_value(value) click to toggle source
# File lib/muwu/destination/destination.rb, line 139
def write_value(value)
  output.print value
end

Private Instance Methods

announce_open() click to toggle source
# File lib/muwu/destination/destination.rb, line 148
def announce_open
  if @output_class == 'file'
    puts "- Writing `#{output_filename}`."
  end
end
destination_file_open() click to toggle source
# File lib/muwu/destination/destination.rb, line 155
def destination_file_open
  filename = File.join(@output_working_directory, @output_filename)
  File.new(filename, 'w')
end
destination_stdout() click to toggle source
# File lib/muwu/destination/destination.rb, line 161
def destination_stdout
  $stdout
end
output_close() click to toggle source
# File lib/muwu/destination/destination.rb, line 166
def output_close
  begin
    if output_is_closed
      raise ProjectExceptionHandler::Fatal.new(ProjectException::OutputNotOpen.new)
    elsif output_is_opened
      output_close_assignment
    end
  end
  margin_to_zero
end
output_close_assignment() click to toggle source
# File lib/muwu/destination/destination.rb, line 178
def output_close_assignment
  if File === @output
    @output.close
    @output = nil
  else
    @output = nil
  end
end
output_open() click to toggle source
# File lib/muwu/destination/destination.rb, line 188
def output_open
  margin_to_zero
  begin
    if output_is_opened
      raise ProjectExceptionHandler::Fatal.new(ProjectException::OutputAlreadyOpen.new)
    elsif output_is_closed
      output_open_assignment
    end
  end
end
output_open_assignment() click to toggle source
# File lib/muwu/destination/destination.rb, line 200
def output_open_assignment
  case @output_class
  when 'file'
    @output = destination_file_open
  when 'stdout'
    @output = destination_stdout
  end
end
render_current_margin() click to toggle source
# File lib/muwu/destination/destination.rb, line 210
def render_current_margin
  (MARGIN * @margin_depth.to_i)
end