Class: Undies::RootNode

Inherits:
Object
  • Object
show all
Defined in:
lib/undies/root_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ RootNode

Returns a new instance of RootNode.



17
18
19
20
# File 'lib/undies/root_node.rb', line 17

def initialize(io)
  @io = io
  @cached = nil
end

Instance Attribute Details

#cachedObject (readonly)

RootNode is specifically used to handle root document markup.



15
16
17
# File 'lib/undies/root_node.rb', line 15

def cached
  @cached
end

#ioObject (readonly)

RootNode is specifically used to handle root document markup.



15
16
17
# File 'lib/undies/root_node.rb', line 15

def io
  @io
end

Instance Method Details

#attrs(*args) ⇒ Object

Raises:



22
23
24
# File 'lib/undies/root_node.rb', line 22

def attrs(*args)
  raise RootAPIError, "can't call '__attrs' at the root node level"
end

#element_node(element_node) ⇒ Object



31
32
33
34
# File 'lib/undies/root_node.rb', line 31

def element_node(element_node)
  write_cached
  @cached = element_node
end

#flushObject



40
41
42
43
44
# File 'lib/undies/root_node.rb', line 40

def flush
  write_cached
  @cached = nil
  self
end

#partial(partial) ⇒ Object



36
37
38
# File 'lib/undies/root_node.rb', line 36

def partial(partial)
  text(partial)
end

#popObject



51
52
53
# File 'lib/undies/root_node.rb', line 51

def pop
  flush
end

#pushObject



46
47
48
49
# File 'lib/undies/root_node.rb', line 46

def push
  @io.push(@cached)
  @cached = nil
end

#text(raw) ⇒ Object



26
27
28
29
# File 'lib/undies/root_node.rb', line 26

def text(raw)
  write_cached
  @cached = "#{@io.line_indent}#{raw.to_s}#{@io.newline}"
end