Class: QED::Demo

Inherits:
Object show all
Defined in:
lib/qed/demo.rb

Overview

The Demo class ecapsulates a demonstrandum script.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Demo

Steup new Demo instance.

Parameters:

  • file (String)

    Path to demo file.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :mode (Symbol)

    Either `:comment` or other for normal mode.

  • :at (Strng)

    Working directory.

  • :applique (Array)

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

  • :scope (Scope)

    Overriding scope, otherwise new Scope instance is created.


40
41
42
43
44
45
# File 'lib/qed/demo.rb', line 40

def initialize(file, options={})
  @file     = file

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

Instance Attribute Details

#fileObject (readonly)

Demonstrandum file.


16
17
18
# File 'lib/qed/demo.rb', line 16

def file
  @file
end

#modeObject (readonly)

Parser mode.


19
20
21
# File 'lib/qed/demo.rb', line 19

def mode
  @mode
end

Instance Method Details

#appliqueObject

Returns a cached Array of Applique modules.


58
59
60
61
62
63
64
65
66
67
68
69
70
# 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_locationsObject

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


79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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_primeObject


73
74
75
# File 'lib/qed/demo.rb', line 73

def applique_prime
  applique.first
end

#directoryObject

Expanded dirname of file.


48
49
50
# File 'lib/qed/demo.rb', line 48

def directory
  @directory ||= File.expand_path(File.dirname(file))
end

#nameObject

File basename less extension.


53
54
55
# File 'lib/qed/demo.rb', line 53

def name
  @name ||= File.basename(file).chomp(File.extname(file))
end

#parserParser

Get a new Parser instance for this demo.

Returns:

  • (Parser)

    parser for this demo


109
110
111
# File 'lib/qed/demo.rb', line 109

def parser
  Parser.new(self, :mode=>mode)
end

#run(options = {}) ⇒ Object

Run demo through Evaluator instance with given observers.


114
115
116
# File 'lib/qed/demo.rb', line 114

def run(options={})
  Evaluator.run(self, options)
end

#stepsArray Also known as: parse

Demo steps, cached from parsing.

Returns:

  • (Array)

    parsed steps


97
98
99
# File 'lib/qed/demo.rb', line 97

def steps
  @steps ||= parser.parse
end