Method: Html2rss::AutoSource::Scraper::Schema.from

Defined in:
lib/html2rss/auto_source/scraper/schema.rb

.from(object) ⇒ Array<Hash>

Returns a flat array of all supported schema objects by recursively traversing the given object.

:reek:DuplicateMethodCall

Parameters:

  • object (Hash, Array, Nokogiri::XML::Element)

Returns:

  • (Array<Hash>)

    the schema_objects, or an empty array



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/html2rss/auto_source/scraper/schema.rb', line 39

def from(object)
  case object
  when Nokogiri::XML::Element
    from(parse_script_tag(object))
  when Hash
    supported_schema_object?(object) ? [object] : object.values.flat_map { |item| from(item) }
  when Array
    object.flat_map { |item| from(item) }
  else
    []
  end
end