module Cardio::Mod::Eat::Edibles
item handling for Mod::Eat
(importables)
Public Instance Methods
edibles()
click to toggle source
list of card attribute hashes @return [Array <Hash>]
# File lib/cardio/mod/eat/edibles.rb, line 8 def edibles explicit_edibles { mods_with_data.map { |mod| mod_edibles mod }.flatten } end
Private Instance Methods
attachment_keys()
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 107 def attachment_keys @attachment_keys ||= Card.uploaders.keys end
each_attachment(hash) { |key, hash| ... }
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 95 def each_attachment hash attachment_keys.each { |key| yield key, hash[key] if hash.key? key } end
each_card_hash(items) { |item| ... }
click to toggle source
for processing that needs to happen on all cards, including fields
# File lib/cardio/mod/eat/edibles.rb, line 74 def each_card_hash items, &block items.each do |item| raise Card::Error, "inedible pod data: #{item}" unless item.is_a? Hash yield item process_fields item, &block end items end
ensure_mod_data_path(paths)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 42 def ensure_mod_data_path paths return [@mod] if paths[@mod] raise "no data directory found for mod #{@mod}".red end
explicit_codename_match?(codename)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 26 def explicit_codename_match? codename codename && (codename == @name[1..-1]) end
explicit_edibles() { || ... }
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 14 def explicit_edibles return yield unless @name yield.select do |edible| if @name.match?(/^\:/) explicit_codename_match? edible[:codename] else explicit_name_match? edible[:name] end end end
explicit_name_match?(name)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 30 def explicit_name_match? name name && (name.to_name == @name.to_name) end
handle_attachments(mod, hash)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 88 def handle_attachments mod, hash each_attachment hash do |key, filename| hash[key] = mod_file mod, filename hash[:mod] = mod.name if hash[:storage_type] == :coded end end
interpret_items(mod, items)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 62 def interpret_items mod, items each_card_hash(items) { |hash| handle_attachments mod, hash } end
items_for_type(mod, type)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 53 def items_for_type mod, type return unless (items = items_from_yaml mod, type) items = items.map do |item| item.is_a?(String) ? items_from_yaml(mod, type, item) : item end.flatten.compact interpret_items mod, items end
items_from_yaml(mod, type, filename=nil)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 66 def items_from_yaml mod, type, filename=nil source = "#{type}#{'/' if filename.present?}#{filename}.yml" return unless (path = mod.subpath "data", source) YAML.load_file path end
mod_edibles(mod)
click to toggle source
@return [Array <Hash>]
# File lib/cardio/mod/eat/edibles.rb, line 49 def mod_edibles mod pod_types.map { |type| items_for_type mod, type }.compact end
mod_file(mod, filename)
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 99 def mod_file mod, filename unless (mod_file_path = mod.subpath "data/files", filename) raise StandardError, "#{filename} not found. "\ "Should be in data/files in #{mod.name} mod." end File.open mod_file_path end
mods_with_data()
click to toggle source
if mod is specified, consider only that mod @return [Array <Cardio::Mod>]
# File lib/cardio/mod/eat/edibles.rb, line 36 def mods_with_data paths = Mod.dirs.subpaths "data" mod_names = @mod ? ensure_mod_data_path(paths) : paths.keys mod_names.map { |mod_name| Mod.fetch mod_name } end
pod_types()
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 111 def pod_types if @pod_type == :all %i[real test] elsif @pod_type [@pod_type] elsif Rails.env.test? %i[real test] else [:real] end end
process_fields(item) { |val| ... }
click to toggle source
# File lib/cardio/mod/eat/edibles.rb, line 84 def process_fields item item[:fields]&.values&.each { |val| yield val if val.is_a? Hash } end