class Hanoi::Jane::CLI

Public Instance Methods

console() click to toggle source
# File lib/hanoi/jane/cli.rb, line 53
def console
  begin
    drop_in = DropIn.new do |d|
      d.height = options[:discs] + options[:height]
      d.discs = options[:discs]
    end

    towers = AnimatedTowers.new do |a|
      a.towers = options[:constrained] ? ConstrainedTowers : RegularTowers
      a.discs = options[:discs]
      a.height = options[:discs] + options[:height]
    end

    [drop_in, towers].each do |source|
      Hanoi::Jane.render_to_console source, options[:interval], options[:fancy]
    end

    puts '%d moves to solve for %d discs' % [towers.towers.total, towers.discs]

  rescue HanoiException => he
    puts he.text
    system('exit')
  end
end
github() click to toggle source
# File lib/hanoi/jane/cli.rb, line 82
def github
  begin
    towers = ConstrainedTowers.deserialise options[:save_path]
  rescue Errno::ENOENT => e
    if e.message == "No such file or directory @ rb_sysopen - #{options[:save_path]}"
      towers = ConstrainedTowers.new options[:discs]
    end
  end

  conf = YAML.load_file "#{ENV['HOME']}/.hanoi-jane/config.yaml"
  Gitpaint.configure do |config|
    config.ssh_key = conf['ssh_key']
    config.username = conf['username']
    config.email = conf['email']
    config.token = conf['token']
  end

  h = Hanoi::Jane.render_to_github towers
  Gitpaint.paint h, message: towers.ternary
  
  unless towers.solved
    towers.move
    towers.serialise options[:save_path]
  end
end
phat() click to toggle source
# File lib/hanoi/jane/cli.rb, line 18
def phat
  grid = JSON.parse(HTTParty.get('http://%s/lights' % options[:phat]).body)['matrix']
  squeegee = Wiper::Squeegee.new do |s|
    s.grid = grid unless grid == []
    s.interval = 0.01
  end

  squeegee.each do |frame|
    Hanoi::Jane.hit_phat frame, options[:phat]
    sleep frame.interval
  end

  drop_in = DropIn.new do |d|
    d.height = 7
    d.discs = options[:discs]
  end

  towers = AnimatedTowers.new do |a|
    a.towers = ConstrainedTowers
    a.discs = options[:discs]
    a.height = 7
  end

  [drop_in, towers].each do |source|
    Hanoi::Jane.render_to_phat source, options[:interval], options[:phat]
  end
end
version() click to toggle source
# File lib/hanoi/jane/cli.rb, line 7
def version
  puts "hanoi version #{VERSION}"
end