Class: StreamParser::HTML::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/stream_parser/html/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



2
3
4
# File 'lib/stream_parser/html/tag.rb', line 2

def attributes
  @attributes
end

#nameObject (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

Parameters:

  • value

    the value to set the attribute self_closing to.



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

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/stream_parser/html/tag.rb', line 28

def opening?
  !@closing
end

#self_closing?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/stream_parser/html/tag.rb', line 20

def self_closing?
  @self_closing
end