Class: PaprikaClient::Recipe
- Inherits:
-
Object
- Object
- PaprikaClient::Recipe
- 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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#calculate_hash ⇒ Object
Recompute the sync hash from the current attributes (excluding "hash").
-
#initialize(attributes = {}) ⇒ Recipe
constructor
A new instance of Recipe.
- #name ⇒ Object
- #nutritional_info ⇒ Object
- #nutritional_info=(value) ⇒ Object
-
#sync_hash ⇒ Object
The sync hash currently stored on the recipe (named to avoid clobbering Ruby's Object#hash).
- #to_h ⇒ Object
- #uid ⇒ Object
-
#with_recomputed_hash ⇒ Object
Attributes with a freshly-computed "hash", ready for upload.
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
#attributes ⇒ Object (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_hash ⇒ Object
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 |
#name ⇒ Object
26 27 28 |
# File 'lib/paprika_client/recipe.rb', line 26 def name self["name"] end |
#nutritional_info ⇒ Object
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_hash ⇒ Object
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_h ⇒ Object
54 55 56 |
# File 'lib/paprika_client/recipe.rb', line 54 def to_h @attributes.dup end |
#uid ⇒ Object
22 23 24 |
# File 'lib/paprika_client/recipe.rb', line 22 def uid self["uid"] end |
#with_recomputed_hash ⇒ Object
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 |