Sha256: 732da458eb6ba78d9900f55e87e0975702e9b03e92ad25b754df48cb117c3e98

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

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(
          description: hash['description'],
          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

1 entries across 1 versions & 1 rubygems

Version Path
weneedfeed-0.8.0 lib/weneedfeed/schema.rb