Class: Mullet::HTML::Parser::OpenElement

Inherits:
Object
  • Object
show all
Defined in:
lib/mullet/html/parser/open_element.rb

Overview

Element where the parser has seen the start tag but not yet seen the end tag.

Constant Summary collapse

XMLNS_ATTRIBUTE =
'xmlns'
XMLNS_ATTRIBUTE_PREFIX =
XMLNS_ATTRIBUTE + ':'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, qualified_name, raw_attributes) ⇒ OpenElement

Returns a new instance of OpenElement.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mullet/html/parser/open_element.rb', line 17

def initialize(parent, qualified_name, raw_attributes)
  # namespace prefix to URI map
  @namespace_declarations = Hash.new()

  @parent = parent

  process_namespace_declarations(raw_attributes)
  @qualified_name = qualified_name
  @prefix, @local_name = extract_prefix_and_local_name(qualified_name)
  @uri = resolve_prefix_to_uri(@prefix)

  @attributes = to_namespace_aware_attributes(raw_attributes)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



15
16
17
# File 'lib/mullet/html/parser/open_element.rb', line 15

def attributes
  @attributes
end

#local_nameObject (readonly)

Returns the value of attribute local_name.



14
15
16
# File 'lib/mullet/html/parser/open_element.rb', line 14

def local_name
  @local_name
end

#namespace_declarationsObject (readonly)

Returns the value of attribute namespace_declarations.



15
16
17
# File 'lib/mullet/html/parser/open_element.rb', line 15

def namespace_declarations
  @namespace_declarations
end

#parentObject (readonly)

Returns the value of attribute parent.



14
15
16
# File 'lib/mullet/html/parser/open_element.rb', line 14

def parent
  @parent
end

#prefixObject (readonly)

Returns the value of attribute prefix.



14
15
16
# File 'lib/mullet/html/parser/open_element.rb', line 14

def prefix
  @prefix
end

#qualified_nameObject (readonly)

Returns the value of attribute qualified_name.



14
15
16
# File 'lib/mullet/html/parser/open_element.rb', line 14

def qualified_name
  @qualified_name
end

#uriObject (readonly)

Returns the value of attribute uri.



14
15
16
# File 'lib/mullet/html/parser/open_element.rb', line 14

def uri
  @uri
end

Instance Method Details

#resolve_prefix_to_uri(prefix) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/mullet/html/parser/open_element.rb', line 31

def resolve_prefix_to_uri(prefix)
  uri = @namespace_declarations.fetch(prefix, nil)
  if uri == nil && @parent != nil
    return @parent.resolve_prefix_to_uri(prefix)
  end
  return uri
end