Class: Undies::Node

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

Direct Known Subclasses

Element

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, opts = {}) ⇒ Node

Returns a new instance of Node.



18
19
20
21
22
23
# File 'lib/undies/node.rb', line 18

def initialize(content, opts={})
  @start_tag = nil
  @end_tag = nil
  @force_pp = opts[:force_pp]
  @content = content
end

Class Method Details

.content(node) ⇒ Object

have as many methods to the class level as possilbe to keep from polluting the public instance methods and to maximize the effectiveness of the Element#method_missing logic



9
10
11
# File 'lib/undies/node.rb', line 9

def self.content(node)
  node.instance_variable_get("@content")
end

.flush(output, node) ⇒ Object



13
14
15
16
# File 'lib/undies/node.rb', line 13

def self.flush(output, node)
  output.pp_use_indent = true if node.force_pp?
  output << self.content(node)
end

Instance Method Details

#==(other_node) ⇒ Object



29
30
31
32
33
# File 'lib/undies/node.rb', line 29

def ==(other_node)
  self.class.content(self) == other_node.class.content(other_node) &&
  self.instance_variable_get("@start_tag") == other_node.instance_variable_get("@start_tag") &&
  self.instance_variable_get("@end_tag") == other_node.instance_variable_get("@end_tag")
end

#force_pp?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/undies/node.rb', line 25

def force_pp?
  !!@force_pp
end