Class: RecipeScrapers::Models::Recipe

Inherits:
Data
  • Object
show all
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.

Examples:

recipe = RecipeScrapers.scrape("https://www.recipetineats.com/crispy-potato-straws-pommes-paille/")
recipe.title                          # => "Crispy potato straws (Pommes Paille)"
recipe.to_h[:parsed_ingredients].first
# => { amount: 1.0, unit: nil, name: "potato, or other starchy or all-rounder potato" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#author ⇒ String? (readonly)

Returns the author, several joined with ", ".

Returns:

  • (String, nil) —

    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.

Returns:

  • (String) —

    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".

Returns:

  • (String, nil) —

    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.

Returns:

  • (Integer, nil) —

    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".

Returns:

  • (String, nil) —

    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".

Returns:

  • (String, nil) —

    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.

Returns:

  • (String, nil) —

    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".

Returns:

  • (Array<String>, nil) —

    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.

Returns:

  • (Array<String>, nil) —

    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.".

Returns:

  • (String) —

    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.

Returns:

  • (String, nil) —

    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.

Returns:



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.

Returns:

  • (Array<String>, nil)


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.

Returns:

  • (String, nil) —

    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.

Returns:

  • (Array<String>, nil) —

    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".

Returns:

  • (Array<String>, nil) —

    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".

Returns:

  • (String, nil) —

    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

Returns the href of every link on the page, as written.

Returns:

  • (Array<String>) —

    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.

Examples:

recipe.nutrients # => { "calories" => "219 kcal", "fatContent" => "7 g" }

Returns:

  • (Hash{String => String}, nil)


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.

Examples:

recipe.parsed_ingredients.first.to_h # => { amount: 1.5, unit: "cups", name: "vegetable oil" }

Returns:



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.

Examples:

recipe.parsed_nutrients.first.to_h # => { name: "calories", unit: "kcal", amount: 219.0 }

Returns:



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.

Returns:

  • (Integer, nil) —

    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.

Returns:

  • (Float, nil) —

    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.

Returns:

  • (Integer, nil) —

    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.

Returns:

  • (String, nil) —

    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.

Returns:

  • (String, nil) —

    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.

Returns:

  • (Integer, nil) —

    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.

Returns:

  • (String) —

    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".

Returns:

  • (String, nil) —

    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.

Returns:

  • (Hash{Symbol => Object})


109
110
111
# File 'lib/recipe_scrapers/models/recipe.rb', line 109

def to_h(&)
  super.transform_values { |value| plain(value) }.to_h(&)
end