module Aqueductron::Drawing

Public Class Methods

draw_end_piece(symbol) click to toggle source
# File lib/aqueductron/drawing.rb, line 7
def self.draw_end_piece(symbol)
  ["\\", " #{symbol}", "/"]
end
draw_mid_piece(description) click to toggle source
# File lib/aqueductron/drawing.rb, line 3
def self.draw_mid_piece(description)
  dashes = "-" * description.length
  [dashes, description, dashes]
end
draw_multiple_paths(paths) click to toggle source
# File lib/aqueductron/drawing.rb, line 14
def self.draw_multiple_paths(paths)
  ducts = paths.keys.map{ |k| Drawing.horizontal_concat(Drawing.draw_mid_piece(" #{k.to_s} "), paths[k].draw) }.flatten(1)
end
horizontal_concat(first, second) click to toggle source
# File lib/aqueductron/drawing.rb, line 18
def self.horizontal_concat(first, second)
  # I <3 Ruby. this kind of recursive ref doesn't work in Scala
  identity = ->(piece,msg) { piece.pass_on(msg, identity)}
  concat_one_of_these= ->(array) {
    ->(piece,msg) {
       (head, *tail) = array
       if (tail.empty?)
         piece.pass_on(msg + head, identity)
       else
         piece.pass_on(msg + head, concat_one_of_these.call(tail))
       end
    }
  }
  centeredSecond = centered_on(first.length, second)
  centered_first = centered_on(second.length, first, padding(first), padding(first))
  duct = Duct.new.custom(concat_one_of_these.call(centeredSecond)).array()
  duct.flow(centered_first).value
end
joint_prefix() click to toggle source
# File lib/aqueductron/drawing.rb, line 10
def self.joint_prefix
   [" / ","<  ", ' \\ ']
end

Private Class Methods

centered_on(length, array, paddingBefore = "", paddingAfter = "") click to toggle source
# File lib/aqueductron/drawing.rb, line 38
def self.centered_on(length, array, paddingBefore = "", paddingAfter = "")
  if (length <= array.length)
    array
  else
    top_spacing = (length - array.length) / 2
    bottom_spacing = ((length - array.length) / 2.0).ceil
    ([paddingBefore] * top_spacing) + array + ([paddingAfter] * bottom_spacing)
  end
end
padding(array) click to toggle source
# File lib/aqueductron/drawing.rb, line 48
def self.padding(array)
  " " * array.first.length
end