class Mg2en::Recipe
This class holds a recipe.
Attributes
cuisine[R]
directions[R]
image[R]
ingredients[R]
name[R]
note[R]
notes[R]
source[R]
summary[R]
url[R]
Public Class Methods
new(r)
click to toggle source
# File lib/mg2en/recipe.rb, line 16 def initialize(r) @name = r['NAME'] @summary = r['SUMMARY'] @note = r['NOTE'] @source = r['SOURCE'] @url = check_url(r['PUBLICATION_PAGE']) @yield = r['YIELD'] @servings = r['SERVINGS'] scale_image(r['IMAGE'].read) if r['IMAGE'] @ingredients = [] r['INGREDIENTS_TREE'].each do |i| ingredient = Mg2en::Ingredient.new(i) @ingredients.push ingredient end @directions = [] r['DIRECTIONS_LIST'].each do |d| direction = Mg2en::Direction.new(d) @directions.push direction end @notes = [] r['NOTES_LIST'] && r['NOTES_LIST'].each { |n| @notes.push n['NOTE_TEXT'] } @tags = [] r['CATEGORIES'] && r['CATEGORIES'].each { |c| @tags.push c['NAME'] } @cuisine = [] r['CUISINE'] && r['CUISINE'].each { |c| @cuisine.push c['NAME']} end
Public Instance Methods
check_url(url)
click to toggle source
# File lib/mg2en/recipe.rb, line 71 def check_url(url) uri = URI.parse(url) if uri.scheme.eql?('http') || uri.scheme.eql?('https') return uri.to_s else return nil end rescue return nil end
enml()
click to toggle source
# File lib/mg2en/recipe.rb, line 48 def enml template_file = Mg2en::Options.defaults[:template] + '.haml' template = File.expand_path("../../../templates/#{template_file}", __FILE__) engine = Haml::Engine.new(File.open(template).read) engine.render(self) end
scale_image(image)
click to toggle source
# File lib/mg2en/recipe.rb, line 56 def scale_image(image) file = Tempfile.new(['thumb', '.jpg']) begin ImageScience.with_image_from_memory(image) do |i| i.cropped_thumbnail(Mg2en::Options.defaults[:image_size]) do |thumb| thumb.save(file.path) end end @image = file.read ensure file.close file.unlink end end