Class: Weneedfeed::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/weneedfeed/schema.rb

Constant Summary collapse

DEFAULT_TITLE =
'Weneedfeed'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Schema

Returns a new instance of Schema.

Parameters:

  • raw (Hash)


19
20
21
# File 'lib/weneedfeed/schema.rb', line 19

def initialize(raw)
  @raw = raw
end

Class Method Details

.load_file(schema_path) ⇒ Weneedfeed::Schema

Parameters:

  • schema_path (String)

Returns:



12
13
14
15
# File 'lib/weneedfeed/schema.rb', line 12

def load_file(schema_path)
  raw = ::YAML.load_file(schema_path, aliases: true)
  new(raw)
end

Instance Method Details

#find_page_schema(page_schema_id) ⇒ Weneedfeed::PageSchema

Parameters:

  • page_schema_id (String, nl)

Returns:



25
26
27
28
29
# File 'lib/weneedfeed/schema.rb', line 25

def find_page_schema(page_schema_id)
  page_schemata.find do |page_schema|
    page_schema.id == page_schema_id
  end
end

#page_idsArray<String>

Returns:

  • (Array<String>)


32
33
34
# File 'lib/weneedfeed/schema.rb', line 32

def page_ids
  page_schemata.map(&:id)
end

#page_schemataArray<Weneedfeed::PageSchema>

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/weneedfeed/schema.rb', line 37

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_image_selector: hash['item_image_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

#titleString

Returns:

  • (String)


55
56
57
# File 'lib/weneedfeed/schema.rb', line 55

def title
  @raw['title'] || DEFAULT_TITLE
end