Class: DocumentBuilder::Tag

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type: nil, selector: nil) ⇒ Tag

Returns a new instance of Tag.



5
6
7
8
9
# File 'lib/document_builder/tag.rb', line 5

def initialize(name, type: nil, selector: nil)
  @name = name
  @selector = selector
  @type = type || Coercion::TextProperty
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/document_builder/tag.rb', line 3

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



3
4
5
# File 'lib/document_builder/tag.rb', line 3

def node
  @node
end

#selectorObject (readonly)

Returns the value of attribute selector.



3
4
5
# File 'lib/document_builder/tag.rb', line 3

def selector
  @selector
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/document_builder/tag.rb', line 3

def type
  @type
end

Instance Method Details

#call(document) ⇒ Object



11
12
13
14
15
16
# File 'lib/document_builder/tag.rb', line 11

def call(document)
  return nil if document.nil?

  @node = selector.nil? ? document : document.attributes[selector]
  type.call(@node)
end