Class: PaprikaClient::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/paprika_client/recipe.rb

Overview

A Paprika recipe. Thin wrapper around the raw attributes hash returned by (and sent to) the sync API. Keys are stored as strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Recipe

Returns a new instance of Recipe.



9
10
11
12
# File 'lib/paprika_client/recipe.rb', line 9

def initialize(attributes = {})
  @attributes = {}
  attributes.each { |k, v| @attributes[k.to_s] = v }
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/paprika_client/recipe.rb', line 7

def attributes
  @attributes
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/paprika_client/recipe.rb', line 14

def [](key)
  @attributes[key.to_s]
end

#[]=(key, value) ⇒ Object



18
19
20
# File 'lib/paprika_client/recipe.rb', line 18

def []=(key, value)
  @attributes[key.to_s] = value
end

#calculate_hashObject

Recompute the sync hash from the current attributes (excluding "hash").



45
46
47
# File 'lib/paprika_client/recipe.rb', line 45

def calculate_hash
  Hashing.digest(@attributes)
end

#nameObject



26
27
28
# File 'lib/paprika_client/recipe.rb', line 26

def name
  self["name"]
end

#nutritional_infoObject



30
31
32
# File 'lib/paprika_client/recipe.rb', line 30

def nutritional_info
  self["nutritional_info"]
end

#nutritional_info=(value) ⇒ Object



34
35
36
# File 'lib/paprika_client/recipe.rb', line 34

def nutritional_info=(value)
  self["nutritional_info"] = value
end

#sync_hashObject

The sync hash currently stored on the recipe (named to avoid clobbering Ruby's Object#hash).



40
41
42
# File 'lib/paprika_client/recipe.rb', line 40

def sync_hash
  self["hash"]
end

#to_hObject



54
55
56
# File 'lib/paprika_client/recipe.rb', line 54

def to_h
  @attributes.dup
end

#uidObject



22
23
24
# File 'lib/paprika_client/recipe.rb', line 22

def uid
  self["uid"]
end

#with_recomputed_hashObject

Attributes with a freshly-computed "hash", ready for upload.



50
51
52
# File 'lib/paprika_client/recipe.rb', line 50

def with_recomputed_hash
  @attributes.merge("hash" => calculate_hash)
end