Class: Speculations::Parser::Context
- Inherits:
-
Object
- Object
- Speculations::Parser::Context
show all
- Defined in:
- lib/speculations/parser/context.rb
Defined Under Namespace
Classes: Example, Include, Setup
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def filename
@filename
end
|
#level ⇒ Object
Returns the value of attribute level.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def level
@level
end
|
#lnb ⇒ Object
Returns the value of attribute lnb.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def lnb
@lnb
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def name
@name
end
|
#orig_filename ⇒ Object
Returns the value of attribute orig_filename.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def orig_filename
@orig_filename
end
|
#parent ⇒ Object
Returns the value of attribute parent.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def parent
@parent
end
|
#potential_name ⇒ Object
Returns the value of attribute potential_name.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def potential_name
@potential_name
end
|
#setup ⇒ Object
Returns the value of attribute setup.
6
7
8
|
# File 'lib/speculations/parser/context.rb', line 6
def setup
@setup
end
|
Instance Method Details
#add_child(name:, lnb:) ⇒ Object
8
9
10
11
12
|
# File 'lib/speculations/parser/context.rb', line 8
def add_child(name:, lnb:)
raise "Illegal nesting" if parent
children << self.class.new(name: name, lnb: lnb, parent: self)
children.last
end
|
#add_example(lnb:, line:) ⇒ Object
14
15
16
17
18
|
# File 'lib/speculations/parser/context.rb', line 14
def add_example(lnb:, line:)
examples << Example.new(lnb: lnb, parent: self, line: line, name: potential_name)
@potential_name = nil
examples.last
end
|
#add_include(lnb:) ⇒ Object
20
21
22
23
|
# File 'lib/speculations/parser/context.rb', line 20
def add_include(lnb:)
includes << Include.new(lnb: lnb, parent: self)
includes.last
end
|
#children ⇒ Object
25
26
27
|
# File 'lib/speculations/parser/context.rb', line 25
def children
@__children__ ||= []
end
|
#examples ⇒ Object
29
30
31
|
# File 'lib/speculations/parser/context.rb', line 29
def examples
@__examples__ ||= []
end
|
#includes ⇒ Object
33
34
35
|
# File 'lib/speculations/parser/context.rb', line 33
def includes
@__includes__ ||= []
end
|
#map_lines(*lines, indent: 0) ⇒ Object
37
38
39
40
|
# File 'lib/speculations/parser/context.rb', line 37
def map_lines(*lines, indent: 0)
prefix = " " * (level + indent)
lines.flatten.map{ |line| "#{prefix}#{line.strip}" }.join("\n")
end
|
#set_name(potential_name) ⇒ Object
42
43
44
|
# File 'lib/speculations/parser/context.rb', line 42
def set_name(potential_name)
@potential_name = potential_name
end
|
#set_setup(lnb:) ⇒ Object
46
47
48
|
# File 'lib/speculations/parser/context.rb', line 46
def set_setup(lnb:)
@setup = Setup.new(lnb: lnb, parent: self)
end
|
#to_code ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/speculations/parser/context.rb', line 50
def to_code
[
,
includes.map(&:to_code),
setup&.to_code,
examples.map(&:to_code),
children.map(&:to_code),
].flatten.compact.join("\n")
end
|