Class: VirtualDOM::VirtualNode

Inherits:
Object
  • Object
show all
Defined in:
lib/virtual_dom/virtual_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params = {}, children = []) ⇒ VirtualNode

Returns a new instance of VirtualNode.



7
8
9
10
11
# File 'lib/virtual_dom/virtual_node.rb', line 7

def initialize(name, params = {}, children = [])
  @name = name
  @params = params
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/virtual_dom/virtual_node.rb', line 5

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/virtual_dom/virtual_node.rb', line 5

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/virtual_dom/virtual_node.rb', line 5

def params
  @params
end

Instance Method Details

#to_sObject



13
14
15
# File 'lib/virtual_dom/virtual_node.rb', line 13

def to_s
  "<#{@name}#{to_s_params}>#{to_s_children}</#{@name}>"
end

#to_s_childrenObject



23
24
25
26
27
28
29
30
# File 'lib/virtual_dom/virtual_node.rb', line 23

def to_s_children
  return @children if @children.is_a?(String)
  return unless @children.any?

  @children
    .map(&:to_s)
    .join
end

#to_s_paramsObject



17
18
19
20
21
# File 'lib/virtual_dom/virtual_node.rb', line 17

def to_s_params
  return unless @params.any?

  " #{@params.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")}"
end