Class: Interscript::Node::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/interscript/node/document.rb,
lib/interscript/utils/helpers.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



6
7
8
9
10
11
12
13
14
# File 'lib/interscript/node/document.rb', line 6

def initialize
  puts "Interscript::Node::Document.new " if $DEBUG
  @metadata = nil
  @tests = nil
  @dependencies = []
  @dep_aliases = {}
  @aliases = {}
  @stages = {}
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



3
4
5
# File 'lib/interscript/node/document.rb', line 3

def aliases
  @aliases
end

#dep_aliasesObject

Returns the value of attribute dep_aliases.



3
4
5
# File 'lib/interscript/node/document.rb', line 3

def dep_aliases
  @dep_aliases
end

#dependenciesObject

Returns the value of attribute dependencies.



3
4
5
# File 'lib/interscript/node/document.rb', line 3

def dependencies
  @dependencies
end

#metadataObject

Returns the value of attribute metadata.



2
3
4
# File 'lib/interscript/node/document.rb', line 2

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/interscript/node/document.rb', line 2

def name
  @name
end

#reversed_fromObject

Returns the value of attribute reversed_from.



4
5
6
# File 'lib/interscript/node/document.rb', line 4

def reversed_from
  @reversed_from
end

#stagesObject

Returns the value of attribute stages.



3
4
5
# File 'lib/interscript/node/document.rb', line 3

def stages
  @stages
end

#testsObject

Returns the value of attribute tests.



2
3
4
# File 'lib/interscript/node/document.rb', line 2

def tests
  @tests
end

Class Method Details

.reverse_name(name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/interscript/node/document.rb', line 50

def self.reverse_name(name)
  newname = (name || "noname").split("-")
  newname[2], newname[3] = newname[3], newname[2] if newname.length >= 4
  newname = newname.join("-")
  if newname == name
    newname.gsub!("-reverse", "")
  end
  if newname == name
    newname += "-reverse"
  end
  newname
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/interscript/node/document.rb', line 63

def ==(other)
  self.class == other.class &&
  self. == other. &&
  self.tests == other.tests &&
  self.stages == other.stages &&
  self.aliases == other.aliases
end

#all_dependenciesObject



32
33
34
35
36
# File 'lib/interscript/node/document.rb', line 32

def all_dependencies
  (dependencies + dependencies.map { |i| i.document.dependencies }).flatten.uniq_by do |i|
    i.full_name
  end
end

#call(str, stage = :main, compiler = $compiler || Interscript::Interpreter, **kwargs) ⇒ Object



23
24
25
# File 'lib/interscript/utils/helpers.rb', line 23

def call(str, stage=:main, compiler=$compiler || Interscript::Interpreter, **kwargs)
  compiler.(self).(str, stage, **kwargs)
end

#imported_aliasesObject



16
17
18
19
20
21
22
# File 'lib/interscript/node/document.rb', line 16

def imported_aliases
  aliases = @aliases
  @dependencies.select(&:import).each do |d|
    aliases = d.document.aliases.merge(aliases)
  end
  aliases
end

#imported_stagesObject



24
25
26
27
28
29
30
# File 'lib/interscript/node/document.rb', line 24

def imported_stages
  stages = @stages
  @dependencies.select(&:import).each do |d|
    stages = d.document.stages.merge(stages)
  end
  stages
end

#reverseObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/interscript/node/document.rb', line 38

def reverse
  @reverse ||= self.class.new.tap do |rdoc|
    rdoc.name = self.class.reverse_name(name)
    rdoc. = &.reverse
    rdoc.tests = tests&.reverse
    rdoc.dependencies = dependencies.map(&:reverse)
    rdoc.stages = stages.transform_values(&:reverse)
    rdoc.dep_aliases = dep_aliases.transform_values(&:reverse)
    rdoc.aliases = aliases
  end
end

#to_hashObject



71
72
73
74
75
76
77
78
# File 'lib/interscript/node/document.rb', line 71

def to_hash
  { :class => self.class.to_s, :metadata => @metadata&.to_hash,
    :tests => @tests&.to_hash,
    :dependencies => @dependencies.map{|x| x.to_hash},
    :dep_aliases => @dep_aliases.transform_values(&:to_hash),
    :aliases => @aliases.transform_values(&:to_hash),
    :stages => @stages.transform_values(&:to_hash) }
end