Class: StreamParser::HTML::Tag
- Inherits:
-
Object
- Object
- StreamParser::HTML::Tag
- Defined in:
- lib/stream_parser/html/tag.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#self_closing ⇒ Object
writeonly
Sets the attribute self_closing.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #closing? ⇒ Boolean
-
#initialize(name, closing = false) ⇒ Tag
constructor
A new instance of Tag.
- #match(name: nil, closing: nil, attributes: nil) ⇒ Object
- #opening? ⇒ Boolean
- #self_closing? ⇒ Boolean
Constructor Details
#initialize(name, closing = false) ⇒ Tag
Returns a new instance of Tag.
5 6 7 8 9 10 |
# File 'lib/stream_parser/html/tag.rb', line 5 def initialize(name, closing=false) @name = name @attributes = {} @closing = closing @self_closing = false end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
2 3 4 |
# File 'lib/stream_parser/html/tag.rb', line 2 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/stream_parser/html/tag.rb', line 2 def name @name end |
#self_closing=(value) ⇒ Object (writeonly)
Sets the attribute self_closing
3 4 5 |
# File 'lib/stream_parser/html/tag.rb', line 3 def self_closing=(value) @self_closing = value end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/stream_parser/html/tag.rb', line 12 def [](key) @attributes[key.to_sym] end |
#[]=(key, value) ⇒ Object
16 17 18 |
# File 'lib/stream_parser/html/tag.rb', line 16 def []=(key, value) @attributes[key.to_sym] = value end |
#closing? ⇒ Boolean
24 25 26 |
# File 'lib/stream_parser/html/tag.rb', line 24 def closing? @closing end |
#match(name: nil, closing: nil, attributes: nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/stream_parser/html/tag.rb', line 32 def match(name: nil, closing: nil, attributes: nil) return false if name && @name != name return false if !closing.nil? && @closing != closing return false if attributes && !attributes.all? { |k,v| @attributes[k] == v } true end |
#opening? ⇒ Boolean
28 29 30 |
# File 'lib/stream_parser/html/tag.rb', line 28 def opening? !@closing end |
#self_closing? ⇒ Boolean
20 21 22 |
# File 'lib/stream_parser/html/tag.rb', line 20 def self_closing? @self_closing end |