class DocumentBuilder::Collection
Attributes
name[R]
node[R]
selector[R]
type[R]
Public Class Methods
new(name, selector:, type:)
click to toggle source
# File lib/document_builder/collection.rb, line 6 def initialize(name, selector:, type:) @name = name @selector = selector @type = type end
Public Instance Methods
call(document)
click to toggle source
# File lib/document_builder/collection.rb, line 12 def call(document) return nil if document.nil? @node = document.xpath(selector) self end
each() { |call| ... }
click to toggle source
# File lib/document_builder/collection.rb, line 18 def each @node.each do |element| yield type.call(element) end end
inspect()
click to toggle source
# File lib/document_builder/collection.rb, line 28 def inspect "#<#{self.class}:0x#{self.object_id.to_s(16)}> Attributes: " + JSON.pretty_generate(to_hash) end
to_hash()
click to toggle source
# File lib/document_builder/collection.rb, line 36 def to_hash entries.map(&:to_hash) end
to_json(*args)
click to toggle source
# File lib/document_builder/collection.rb, line 32 def to_json(*args) JSON.generate(to_hash) end
to_s(*args)
click to toggle source
# File lib/document_builder/collection.rb, line 24 def to_s(*args) JSON.pretty_generate(to_hash) end