Class: Theseus::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/theseus/cli.rb

Constant Summary collapse

TYPE_MAP =
{
  "ortho"   => Theseus::OrthogonalMaze,
  "delta"   => Theseus::DeltaMaze,
  "sigma"   => Theseus::SigmaMaze,
  "upsilon" => Theseus::UpsilonMaze,
}
ALGO_MAP =
{
  "backtrack" => Theseus::Algorithms::RecursiveBacktracker,
  "kruskal"   => Theseus::Algorithms::Kruskal,
  "prim"      => Theseus::Algorithms::Prim,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/theseus/cli.rb', line 40

def initialize(*args)
  args.flatten!

  @animate = false
  @delay = 50
  @output = "maze"
  @sparse = 0
  @unicursal = false
  @type = "ortho"
  @format = :ascii
  @solution = nil

  @png_opts = Theseus::Formatters::PNG::DEFAULTS.dup
  @maze_opts = { mask: nil, width: nil, height: nil,
    randomness: 50, weave: 0, symmetry: :none, braid: 0, wrap: :none,
    entrance: nil, exit: nil, algorithm: ALGO_MAP["backtrack"] }

  option_parser.parse!(args)

  if args.any?
    abort "extra arguments detected: #{args.inspect}"
  end

  normalize_settings!
end

Instance Attribute Details

#animateObject

Returns the value of attribute animate.



28
29
30
# File 'lib/theseus/cli.rb', line 28

def animate
  @animate
end

#delayObject

Returns the value of attribute delay.



29
30
31
# File 'lib/theseus/cli.rb', line 29

def delay
  @delay
end

#formatObject

Returns the value of attribute format.



34
35
36
# File 'lib/theseus/cli.rb', line 34

def format
  @format
end

#maze_optsObject (readonly)

Returns the value of attribute maze_opts.



37
38
39
# File 'lib/theseus/cli.rb', line 37

def maze_opts
  @maze_opts
end

#outputObject

Returns the value of attribute output.



30
31
32
# File 'lib/theseus/cli.rb', line 30

def output
  @output
end

#png_optsObject (readonly)

Returns the value of attribute png_opts.



38
39
40
# File 'lib/theseus/cli.rb', line 38

def png_opts
  @png_opts
end

#solutionObject

Returns the value of attribute solution.



35
36
37
# File 'lib/theseus/cli.rb', line 35

def solution
  @solution
end

#sparseObject

Returns the value of attribute sparse.



31
32
33
# File 'lib/theseus/cli.rb', line 31

def sparse
  @sparse
end

#typeObject

Returns the value of attribute type.



33
34
35
# File 'lib/theseus/cli.rb', line 33

def type
  @type
end

#unicursalObject

Returns the value of attribute unicursal.



32
33
34
# File 'lib/theseus/cli.rb', line 32

def unicursal
  @unicursal
end

Class Method Details

.run(*args) ⇒ Object



24
25
26
# File 'lib/theseus/cli.rb', line 24

def self.run(*args)
  new(*args).run
end

Instance Method Details

#runObject



66
67
68
69
70
71
72
# File 'lib/theseus/cli.rb', line 66

def run
  if @animate
    run_animation
  else
    run_static
  end
end