Class: ComponentEmbeddedRuby::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, attributes, children) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
# File 'lib/component_embedded_ruby/node.rb', line 7

def initialize(tag, attributes, children)
  @tag = tag
  @attributes = attributes
  @children = children
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/component_embedded_ruby/node.rb', line 5

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/component_embedded_ruby/node.rb', line 5

def children
  @children
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/component_embedded_ruby/node.rb', line 5

def tag
  @tag
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/component_embedded_ruby/node.rb', line 13

def ==(other)
  if other
    other.tag == tag && other.attributes == attributes && other.children == children
  else
    false
  end
end

#component?Boolean

If the tag starts with a capital, we assume it’s a component

Returns:

  • (Boolean)


26
27
28
# File 'lib/component_embedded_ruby/node.rb', line 26

def component?
  @_component ||= tag && !!/[[:upper:]]/.match(tag[0])
end

#component_classObject



21
22
23
# File 'lib/component_embedded_ruby/node.rb', line 21

def component_class
  @_component_class = Object.const_get(tag)
end

#html?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/component_embedded_ruby/node.rb', line 42

def html?
  !component? && tag
end

#output_ruby?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/component_embedded_ruby/node.rb', line 34

def output_ruby?
  ruby? && children.output
end

#ruby?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/component_embedded_ruby/node.rb', line 30

def ruby?
  children.is_a?(Eval)
end

#text?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/component_embedded_ruby/node.rb', line 38

def text?
  tag.nil? && !ruby?
end