Sha256: ca83c05856b397e19c0999aa0ad0503d3f24ccd3d519d5e9aebc24cd925d51ec

Contents?: true

Size: 701 Bytes

Versions: 2

Compression:

Stored size: 701 Bytes

Contents

module Punchfork
  
  # Wrapper for recipe search results.  Provides dot syntax support.
  class Recipe
    
    def initialize(*args)
      @hash = args[0]
      @attributes = {}
      @hash.each do |k, v|
        instance_variable_set("@#{k}", v)
        self.class.class_eval{attr_reader k}
        @attributes[k] = v
      end
    end
    
    attr_reader :attributes
    
    def secure_thumb
      return Recipe.secure_url(thumb)
    end
    
    def self.secure_url(url)
      return url if url.match(/^https/)
      uri = URI.parse(url).tap{ |uri| uri.scheme = 'https'; uri.path = File.join('/', uri.host, uri.path); uri.host = 's3.amazonaws.com' }
      return uri.to_s
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
punchfork-0.0.7 lib/punchfork/recipe.rb
punchfork-0.0.6 lib/punchfork/recipe.rb