module RecipeStore
Constants
- PLUGIN_NAME
- RECIPES_KEY
Public Instance Methods
Source
# File lib/recipe_store.rb, line 41 def add_recipe(network:, channel:, nick:, title:, ingredients:, instructions:, source:, tags: [], store: RabbotDb, received_at: nil) recipe = { "id" => generate_id, "nick" => Normalize.nick(nick), "title" => title.to_s.strip, "ingredients" => Array(ingredients).map(&:to_s).map(&:strip).reject(&:empty?), "instructions" => instructions.to_s.strip, "tags" => Array(tags).map(&:to_s).map(&:strip).reject(&:empty?), "source" => source.to_s.strip, "added_at" => received_at || store.iso_time } recipes = load_recipes(network: network, channel: channel, store: store) recipes << recipe save_recipes(network: network, channel: channel, recipes: recipes, store: store) recipe end
Source
# File lib/recipe_store.rb, line 68 def format_remove_last_reply(result) return result[:error] if result[:error] recipe = result[:recipe] "Removed #{recipe['id']} — #{recipe['title']}." end
Source
# File lib/recipe_store.rb, line 13 def load_recipes(network:, channel:, store: RabbotDb) Array(store.get_plugin_json( plugin: PLUGIN_NAME, key: RECIPES_KEY, network: network, channel: channel, default: [] )) end
Source
# File lib/recipe_store.rb, line 37 def parse_ingredients(text) text.to_s.split(/,|\band\b/i).map(&:strip).reject(&:empty?) end
Source
# File lib/recipe_store.rb, line 59 def remove_last_recipe!(network:, channel:, store: RabbotDb) recipes = load_recipes(network: network, channel: channel, store: store) return { error: "No recipes saved yet.", recipe: nil } if recipes.empty? removed = recipes.pop save_recipes(network: network, channel: channel, recipes: recipes, store: store) { recipe: removed } end
Source
# File lib/recipe_store.rb, line 23 def save_recipes(network:, channel:, recipes:, store: RabbotDb) store.set_plugin_json( plugin: PLUGIN_NAME, key: RECIPES_KEY, network: network, channel: channel, value: recipes ) end