Class: RecipeScrapers::Models::Recipe
- Inherits:
-
Data
- Object
- Data
- RecipeScrapers::Models::Recipe
- Defined in:
- lib/recipe_scrapers/models/recipe.rb
Overview
The recipe a page holds, with every field already read. RecipeScrapers.scrape and RecipeScrapers.parse return one. It is a Ruby Data object: frozen, compared by value, and free of the page it came from. A field the page does not publish is nil.
#to_h converts the nested value objects too, so the result holds only strings, numbers, arrays and hashes, ready for JSON.
Instance Attribute Summary collapse
-
#author ⇒ String?
readonly
The author, several joined with ", ".
-
#canonical_url ⇒ String
readonly
The canonical link of the page resolved against #url, or the url itself when the page has none.
-
#category ⇒ String?
readonly
The course, such as "Dessert".
-
#cook_time ⇒ Integer?
readonly
The cooking time in minutes.
-
#cooking_method ⇒ String?
readonly
How it is cooked, such as "Baking".
-
#cuisine ⇒ String?
readonly
The cuisine, such as "Italian".
-
#description ⇒ String?
readonly
A sentence or short paragraph about the recipe.
-
#dietary_restrictions ⇒ Array<String>?
readonly
The diets the recipe suits, such as "VeganDiet".
-
#equipment ⇒ Array<String>?
readonly
The tools a site declares, schema.org has none.
-
#host ⇒ String
readonly
The host of #url, without "www.".
-
#image ⇒ String?
readonly
The address of the main image, resolved against #url.
-
#ingredient_groups ⇒ Array<Models::IngredientGroup>?
readonly
The ingredients in the groups the page shows, such as "For the sauce".
-
#ingredients ⇒ Array<String>?
readonly
The ingredient lines as the page writes them.
-
#instructions ⇒ String?
readonly
The steps joined with newlines.
-
#instructions_list ⇒ Array<String>?
readonly
The steps, with section headings as their own entries.
-
#keywords ⇒ Array<String>?
readonly
The keywords, without facet entries such as "diet: vegan".
-
#language ⇒ String?
readonly
The language tag of the recipe, such as "en-US".
-
#links ⇒ Array<String>
readonly
The href of every link on the page, as written.
-
#nutrients ⇒ Hash{String => String}?
readonly
The nutrition facts as the page publishes them, keyed by the schema.org property name.
-
#parsed_ingredients ⇒ Array<Models::Ingredient>?
readonly
Every line of #ingredients, in the same order, split into an amount, a unit and a name.
-
#parsed_nutrients ⇒ Array<Models::Nutrient>?
readonly
Every entry of #nutrients, in the order the page lists them, split into a name, a unit and an amount.
-
#prep_time ⇒ Integer?
readonly
The preparation time in minutes.
-
#ratings ⇒ Float?
readonly
The average rating.
-
#ratings_count ⇒ Integer?
readonly
How many ratings the average is made of.
-
#site_name ⇒ String?
readonly
The name of the website.
-
#title ⇒ String?
readonly
The name of the recipe.
-
#total_time ⇒ Integer?
readonly
The total time in minutes.
-
#url ⇒ String
readonly
The address the recipe was read from.
-
#yields ⇒ String?
readonly
How much it makes, as "4 servings" or "12 items".
Instance Method Summary collapse
-
#to_h ⇒ Hash{Symbol => Object}
The recipe as plain data.
Instance Attribute Details
#author ⇒ String? (readonly)
Returns the author, several joined with ", ".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#canonical_url ⇒ String (readonly)
Returns the canonical link of the page resolved against #url, or the url itself when the page has none.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#category ⇒ String? (readonly)
Returns the course, such as "Dessert".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#cook_time ⇒ Integer? (readonly)
Returns the cooking time in minutes.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#cooking_method ⇒ String? (readonly)
Returns how it is cooked, such as "Baking".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#cuisine ⇒ String? (readonly)
Returns the cuisine, such as "Italian".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#description ⇒ String? (readonly)
Returns a sentence or short paragraph about the recipe.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#dietary_restrictions ⇒ Array<String>? (readonly)
Returns the diets the recipe suits, such as "VeganDiet".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#equipment ⇒ Array<String>? (readonly)
Returns the tools a site declares, schema.org has none.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#host ⇒ String (readonly)
Returns the host of #url, without "www.".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#image ⇒ String? (readonly)
Returns the address of the main image, resolved against #url.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#ingredient_groups ⇒ Array<Models::IngredientGroup>? (readonly)
The ingredients in the groups the page shows, such as "For the sauce". The groups come from the HTML when the page marks them up, otherwise from the heading lines of the ingredient list. A page without groups gives one group with a nil purpose.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#ingredients ⇒ Array<String>? (readonly)
The ingredient lines as the page writes them. A line with no letter and no digit, such as "*", is a separator and left out. A line that ends in a colon and has no digit, such as "For the sauce:", is a group heading and goes to #ingredient_groups instead. See #parsed_ingredients.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#instructions ⇒ String? (readonly)
Returns the steps joined with newlines.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#instructions_list ⇒ Array<String>? (readonly)
Returns the steps, with section headings as their own entries.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#keywords ⇒ Array<String>? (readonly)
Returns the keywords, without facet entries such as "diet: vegan".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#language ⇒ String? (readonly)
Returns the language tag of the recipe, such as "en-US".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#links ⇒ Array<String> (readonly)
Returns the href of every link on the page, as written.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#nutrients ⇒ Hash{String => String}? (readonly)
The nutrition facts as the page publishes them, keyed by the schema.org property name. Nothing is parsed here. See #parsed_nutrients.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#parsed_ingredients ⇒ Array<Models::Ingredient>? (readonly)
Every line of #ingredients, in the same order, split into an amount, a unit and a name.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#parsed_nutrients ⇒ Array<Models::Nutrient>? (readonly)
Every entry of #nutrients, in the order the page lists them, split into a name, a unit and an amount. The name is the key the page uses. A value with no number is left out.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#prep_time ⇒ Integer? (readonly)
Returns the preparation time in minutes.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#ratings ⇒ Float? (readonly)
Returns the average rating.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#ratings_count ⇒ Integer? (readonly)
Returns how many ratings the average is made of.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#site_name ⇒ String? (readonly)
Returns the name of the website.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#title ⇒ String? (readonly)
Returns the name of the recipe.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#total_time ⇒ Integer? (readonly)
Returns the total time in minutes.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#url ⇒ String (readonly)
Returns the address the recipe was read from.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
#yields ⇒ String? (readonly)
Returns how much it makes, as "4 servings" or "12 items".
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 100 Recipe = Data.define( :url, :title, :author, :site_name, :language, :canonical_url, :host, :description, :image, :ingredients, :parsed_ingredients, :ingredient_groups, :instructions_list, :instructions, :category, :cuisine, :cooking_method, :keywords, :dietary_restrictions, :equipment, :yields, :total_time, :prep_time, :cook_time, :nutrients, :parsed_nutrients, :ratings, :ratings_count, :links ) do # The recipe as plain data. Every nested value object becomes a hash as well. # # @return [Hash{Symbol => Object}] def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end private def plain(value) case value when Data then plain(value.to_h) when Hash then value.transform_values { |item| plain(item) } when Array then value.map { |item| plain(item) } else value end end end |
Instance Method Details
#to_h ⇒ Hash{Symbol => Object}
The recipe as plain data. Every nested value object becomes a hash as well.
109 110 111 |
# File 'lib/recipe_scrapers/models/recipe.rb', line 109 def to_h(&) super.transform_values { |value| plain(value) }.to_h(&) end |