Class: LazyPP::RenderState
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #add_parent(p) ⇒ Object
- #gen_header! ⇒ Object
- #gen_header? ⇒ Boolean
- #indent(by = 1) ⇒ Object
-
#indentation ⇒ Object
RenderState.new(@opts.merge(indent: @opts+by)).
-
#initialize(opts = {}) ⇒ RenderState
constructor
A new instance of RenderState.
- #last_parent ⇒ Object
- #new(opts = {}) ⇒ Object
- #no_header ⇒ Object
- #parent_names ⇒ Object
-
#parents ⇒ Object
(also: #parent)
def parent=(p) @opts=Array.wrap(p).compact end.
- #program ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ RenderState
Returns a new instance of RenderState.
84 85 86 87 88 |
# File 'lib/readable-cpp/nodes.rb', line 84 def initialize opts={} @opts = { indent: 0, parent: [], program: nil, namespace: [] }.merge(opts.is_a?(RenderState) ? opts.opts : opts) end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
83 84 85 |
# File 'lib/readable-cpp/nodes.rb', line 83 def opts @opts end |
Instance Method Details
#add_parent(p) ⇒ Object
102 103 104 |
# File 'lib/readable-cpp/nodes.rb', line 102 def add_parent(p) new(parent: parent+[p]) end |
#gen_header! ⇒ Object
93 |
# File 'lib/readable-cpp/nodes.rb', line 93 def gen_header!() new(gen_header: true) end |
#gen_header? ⇒ Boolean
92 |
# File 'lib/readable-cpp/nodes.rb', line 92 def gen_header?() !!@opts[:gen_header] end |
#indent(by = 1) ⇒ Object
106 107 108 109 |
# File 'lib/readable-cpp/nodes.rb', line 106 def indent(by=1) new(indent: @opts[:indent] + by) #RenderState.new(@opts.merge(indent: @opts[:indent]+by)) end |
#indentation ⇒ Object
RenderState.new(@opts.merge(indent: @opts+by))
110 |
# File 'lib/readable-cpp/nodes.rb', line 110 def indentation() ' '*@opts[:indent] end |
#last_parent ⇒ Object
101 |
# File 'lib/readable-cpp/nodes.rb', line 101 def last_parent() parent.last.name.to_cpp RenderState.new end |
#new(opts = {}) ⇒ Object
89 90 91 |
# File 'lib/readable-cpp/nodes.rb', line 89 def new opts={} RenderState.new(@opts.merge opts) end |
#no_header ⇒ Object
94 |
# File 'lib/readable-cpp/nodes.rb', line 94 def no_header() new(gen_header: false) end |
#parent_names ⇒ Object
100 |
# File 'lib/readable-cpp/nodes.rb', line 100 def parent_names() parent.map{|p|p.name.to_cpp self}.join('::') end |
#parents ⇒ Object Also known as: parent
98 |
# File 'lib/readable-cpp/nodes.rb', line 98 def parents() @opts[:parent] end |
#program ⇒ Object
105 |
# File 'lib/readable-cpp/nodes.rb', line 105 def program() @opts[:program] end |