Sha256: 4cab34d325bfb4e02c76ce40469f577f73f935496d12c245efec11089f4fdfb3

Contents?: true

Size: 1007 Bytes

Versions: 3

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module Weneedfeed
  class Schema
    # @param [Hash] raw
    def initialize(raw)
      @raw = raw
    end

    # @param [String, nl] page_schema_id
    # @return [Weneedfeed::PageSchema]
    def find_page_schema(page_schema_id)
      page_schemata.find do |page_schema|
        page_schema.id == page_schema_id
      end
    end

    # @return [Array<String>]
    def page_ids
      page_schemata.map(&:id)
    end

    # @return [Array<Weneedfeed::PageSchema>]
    def page_schemata
      @raw['pages'].map do |hash|
        ::Weneedfeed::PageSchema.new(
          id: hash['id'],
          item_description_selector: hash['item_description_selector'],
          item_link_selector: hash['item_link_selector'],
          item_time_selector: hash['item_time_selector'],
          item_title_selector: hash['item_title_selector'],
          item_selector: hash['item_selector'],
          title: hash['title'],
          url: hash['url'],
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
weneedfeed-0.7.2 lib/weneedfeed/schema.rb
weneedfeed-0.7.1 lib/weneedfeed/schema.rb
weneedfeed-0.7.0 lib/weneedfeed/schema.rb