Class: Weneedfeed::Schema
- Inherits:
-
Object
- Object
- Weneedfeed::Schema
- Defined in:
- lib/weneedfeed/schema.rb
Constant Summary collapse
- DEFAULT_TITLE =
'Weneedfeed'
Class Method Summary collapse
Instance Method Summary collapse
- #find_page_schema(page_schema_id) ⇒ Weneedfeed::PageSchema
-
#initialize(raw) ⇒ Schema
constructor
A new instance of Schema.
- #page_ids ⇒ Array<String>
- #page_schemata ⇒ Array<Weneedfeed::PageSchema>
- #title ⇒ String
Constructor Details
#initialize(raw) ⇒ Schema
Returns a new instance of Schema.
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
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
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_ids ⇒ Array<String>
32 33 34 |
# File 'lib/weneedfeed/schema.rb', line 32 def page_ids page_schemata.map(&:id) end |
#page_schemata ⇒ Array<Weneedfeed::PageSchema>
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 |
#title ⇒ String
55 56 57 |
# File 'lib/weneedfeed/schema.rb', line 55 def title @raw['title'] || DEFAULT_TITLE end |