Class: Shuwar::Stdlib::Nokogiri::HtmlTag
- Inherits:
-
Object
- Object
- Shuwar::Stdlib::Nokogiri::HtmlTag
- Defined in:
- lib/shuwar/stdlib/nokogiri.rb
Instance Method Summary collapse
- #add_to(a) ⇒ Object
-
#initialize(name, attrs, *children) ⇒ HtmlTag
constructor
A new instance of HtmlTag.
Constructor Details
#initialize(name, attrs, *children) ⇒ HtmlTag
Returns a new instance of HtmlTag.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shuwar/stdlib/nokogiri.rb', line 14 def initialize(name, attrs, *children) @name = name.to_s @attrs = attrs.to_h if children.all? {|a| a.is_a? String} # Multi strings should get a space between them @children = [children.join(" ")] else @children = children end end |
Instance Method Details
#add_to(a) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shuwar/stdlib/nokogiri.rb', line 25 def add_to(a) ele = a.document.create_element @name, @attrs @children.each do |c| case c when String then ele << c else c.add_to ele end end a << ele end |