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.



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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/component_embedded_ruby/node.rb', line 3

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



3
4
5
# File 'lib/component_embedded_ruby/node.rb', line 3

def children
  @children
end

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/component_embedded_ruby/node.rb', line 3

def tag
  @tag
end

Instance Method Details

#==(other) ⇒ Object



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

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)


24
25
26
# File 'lib/component_embedded_ruby/node.rb', line 24

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

#component_classObject



19
20
21
# File 'lib/component_embedded_ruby/node.rb', line 19

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

#html?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/component_embedded_ruby/node.rb', line 40

def html?
  !component? && tag
end

#output_ruby?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/component_embedded_ruby/node.rb', line 32

def output_ruby?
  ruby? && children.output
end

#ruby?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/component_embedded_ruby/node.rb', line 28

def ruby?
  children.is_a?(Eval)
end

#text?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/component_embedded_ruby/node.rb', line 36

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