Class: Undies::Element::Closed

Inherits:
Object
  • Object
show all
Includes:
CSSProxy, MergeAttrs
Defined in:
lib/undies/element.rb

Constant Summary

Constants included from CSSProxy

Undies::Element::CSSProxy::CLASS_METH_REGEX, Undies::Element::CSSProxy::ID_METH_REGEX

Instance Method Summary collapse

Methods included from MergeAttrs

#__attrs

Methods included from CSSProxy

#method_missing, #respond_to?

Constructor Details

#initialize(name, attrs = {}) ⇒ Closed

Returns a new instance of Closed.



140
141
142
143
144
# File 'lib/undies/element.rb', line 140

def initialize(name, attrs={})
  @name    = name.to_s
  @attrs   = {}
  proxy([attrs])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Undies::Element::CSSProxy

Instance Method Details

#==(other) ⇒ Object



163
164
165
166
# File 'lib/undies/element.rb', line 163

def ==(other)
  other.instance_variable_get("@name")  == @name  &&
  other.instance_variable_get("@attrs") == @attrs
end

#__buildObject

closed elements should have no build so do nothing



154
# File 'lib/undies/element.rb', line 154

def __build; end

#__contentObject

closed elements have no content



151
# File 'lib/undies/element.rb', line 151

def __content; ''; end

#__end_tagObject

closed elements have no end tag



157
# File 'lib/undies/element.rb', line 157

def __end_tag; ''; end

#__start_tagObject



146
147
148
# File 'lib/undies/element.rb', line 146

def __start_tag
  "<#{@name}#{Undies::Element.hash_attrs(@attrs)} />"
end

#to_sObject



159
160
161
# File 'lib/undies/element.rb', line 159

def to_s
  Undies::Raw.new("#{__start_tag}")
end

#to_str(*args) ⇒ Object Also known as: inspect

overriding this because the base Node class defines a ‘to_s’ method that needs to be honored



170
171
172
173
# File 'lib/undies/element.rb', line 170

def to_str(*args)
  "Undies::Element::Closed:#{self.object_id} " +
  "@name=#{@name.inspect}, @attrs=#{@attrs.inspect}"
end