class QED::Demo

The Demo class ecapsulates a demonstrandum script.

Attributes

file[R]

Demonstrandum file.

mode[R]

Parser mode.

Public Class Methods

new(file, options={}) click to toggle source

Steup new Demo instance.

@param [String] file

Path to demo file.

@param [Hash] options

@option options [Symbol] :mode

Either `:comment` or other for normal mode.

@option options [Strng] :at

Working directory.

@option options [Array] :applique

Overriding applique. Used to import demos into other demos safely.

@option options [Scope] :scope

Overriding scope, otherwise new Scope instance is created.
# File lib/qed/demo.rb, line 40
def initialize(file, options={})
  @file     = file

  @mode     = options[:mode]
  @applique = options[:applique]
end

Public Instance Methods

applique() click to toggle source

Returns a cached Array of Applique modules.

# File lib/qed/demo.rb, line 58
def applique
  @applique ||= (
    list = [Applique.new]
    applique_locations.each do |location|
      #Dir[location + '/**/*'].each do |file|
      Dir[location + '/*'].each do |file|
        next if File.directory?(file)
        list << Applique.for(file)
      end
    end
    list
  )
end
applique_locations() click to toggle source

Returns a list of applique directories to be used by this demonstrastion.

# File lib/qed/demo.rb, line 79
def applique_locations
  @applique_locations ||= (
    locations = []
    dirpath = Pathname.new(File.dirname(file))
    dirpath.ascend do |path|
      break if path == Dir.pwd
      dir = File.join(path, 'applique')
      if File.directory?(dir)
        locations << dir
      end
    end
    locations
  )
end
applique_prime() click to toggle source
# File lib/qed/demo.rb, line 73
def applique_prime
  applique.first
end
directory() click to toggle source

Expanded dirname of file.

# File lib/qed/demo.rb, line 48
def directory
  @directory ||= File.expand_path(File.dirname(file))
end
name() click to toggle source

File basename less extension.

# File lib/qed/demo.rb, line 53
def name
  @name ||= File.basename(file).chomp(File.extname(file))
end
parse()

Parse and cache demonstration script.

@return [Array] list of steps (abstract syntax tree)

Alias for: steps
parser() click to toggle source

Get a new Parser instance for this demo.

@return [Parser] parser for this demo

# File lib/qed/demo.rb, line 109
def parser
  Parser.new(self, :mode=>mode)
end
run(options={}) click to toggle source

Run demo through {Evaluator} instance with given observers.

# File lib/qed/demo.rb, line 114
def run(options={})
  Evaluator.run(self, options)
end
steps() click to toggle source

Demo steps, cached from parsing.

@return [Array] parsed steps

# File lib/qed/demo.rb, line 97
def steps
  @steps ||= parser.parse
end
Also aliased as: parse