Class: RKit::Parser::Tree

Inherits:
Object show all
Defined in:
lib/r_kit/parser/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, tag: :document, frame:) ⇒ Tree

Returns a new instance of Tree.



5
6
7
8
9
10
# File 'lib/r_kit/parser/tree.rb', line 5

def initialize raw, tag: :document, frame:;
  @raw = raw
  @tag = tag

  @frame = frame
end

Instance Attribute Details

#frameObject

Returns the value of attribute frame.



3
4
5
# File 'lib/r_kit/parser/tree.rb', line 3

def frame
  @frame
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/r_kit/parser/tree.rb', line 3

def raw
  @raw
end

#tagObject

Returns the value of attribute tag.



3
4
5
# File 'lib/r_kit/parser/tree.rb', line 3

def tag
  @tag
end

Instance Method Details

#branchesObject



12
13
14
15
16
# File 'lib/r_kit/parser/tree.rb', line 12

def branches
  raw.split(/\n{2,}/).map do |raw_block|
    RKit::Parser::Leaf.new(raw_block, frame: frame)
  end
end

#parsedObject



18
19
20
# File 'lib/r_kit/parser/tree.rb', line 18

def parsed
  branches.map(&:parsed).join("")
end