class Terminator

Attributes

demands[RW]
shell[RW]

Public Class Methods

new(shell: Shell) click to toggle source
# File lib/dunmanifestin/terminator.rb, line 6
def initialize(shell: Shell)
  @shell = shell
end

Public Instance Methods

address(demands) click to toggle source
# File lib/dunmanifestin/terminator.rb, line 10
def address demands
  self.demands = demands
  print interactive_banner if interactive
  construction_loop
end

Private Instance Methods

chomp() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 60
def chomp
  demands[:chomp]
end
coarse_seed() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 92
def coarse_seed
  demands[:coarse_seed]
end
construction_loop() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 20
def construction_loop
  fulltext = ""
  while true
    volume.times do
      text = Phrase.new(phrasing).reify genre
      fulltext += "\n#{text}"
      text += "\n" unless chomp
      shell.puts text
    end

    `echo #{fulltext.inspect} | pbcopy $1` if copy

    break unless interactive
    break if get_from_prompt == 'quit'
  end
end
copy() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 64
def copy
  demands[:copy]
end
default_genre_path() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 100
def default_genre_path
  File.join(*%W(#{File.dirname(__FILE__)} .. .. default-genre))
end
demanded_file() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 80
def demanded_file
  demands[:file]
end
demanded_file_contents() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 84
def demanded_file_contents
  demanded_file && File.read(demanded_file)
end
demanded_genres() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 76
def demanded_genres
  demands[:genre] ? demands[:genre].split(':') : []
end
demanded_phrase() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 88
def demanded_phrase
  demands[:phrase]
end
fine_seed() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 96
def fine_seed
  demands[:fine_seed]
end
genre() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 37
def genre
  @genre ||= Genre.from_directories genre_directories
end
genre_directories() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 41
def genre_directories
  ([default_genre_path] + demanded_genres).reject(&:empty?)
end
get_from_prompt() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 49
def get_from_prompt
  shell.print "dunmanifestin > "
  shell.gets.chomp
end
interactive() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 72
def interactive
  demands[:interactive]
end
interactive_banner() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 54
def interactive_banner
  message = "Type 'quit' to exit the prompt. Press return to generate more output."
  bar = "-"*message.length
  [bar, message, bar].join "\n"
end
phrasing() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 45
def phrasing
  demanded_phrase || demanded_file_contents || '[root]'
end
volume() click to toggle source
# File lib/dunmanifestin/terminator.rb, line 68
def volume
  demands[:count] || 1
end