module ContentProviders module Emotions # Allows participants to record all of yesterday's emotions class NewYesterdayProvider < BitCore::ContentProvider Description = Struct.new(:name, :is_positive) Rating = Struct.new(:description, :value) def render_current(options) context = options.view_context participant = options.participant context.render( template: "think_feel_do_engine/emotions/new_yesterday", locals: { create_path: context.participant_data_path, emotional_ratings: emotional_ratings(participant), participant: participant, ratings: ratings }) end def data_attributes [ :emotion_id, :is_positive, :participant_id, :rating ] end def data_class_name "EmotionalRating" end def emotional_ratings(participant) descriptions.map do |description| participant .emotional_ratings .build( emotion: emotions(participant) .find_or_create_by!(name: description.name), is_positive: description.is_positive) end end def show_nav_link? false end private def descriptions [ Description.new("amused, fun-loving", true), Description.new("angry, irritated, frustrated", false), Description.new("anxious, scared", false), Description.new("awe, wonder, inspiration", true), Description.new("bored", false), Description.new("contempt, score, disdain", false), Description.new("content", false), Description.new("disgusted", false), Description.new("embarrassed", false), Description.new("excited, eager, enthusiastic", true), Description.new("grateful", true), Description.new("guilty", false), Description.new("happy", true), Description.new("hatred, disgust, suspicion", false), Description.new("hopeful, optimistic", true), Description.new("interested", true), Description.new("lonely, rejected", false), Description.new("love, closeness, trust", true), Description.new("proud, confident", true), Description.new("sad", false), Description.new("stressed, overwhelmed", false), Description.new("sympathy, compassion", true), Description.new("relieved", true) ] end def emotions(participant) @emotions ||= participant.emotions end def ratings [ Rating.new("Not at all", 0), Rating.new("A little bit", 1), Rating.new("Sometimes", 2), Rating.new("Frequently", 3), Rating.new("All the time", 4) ] end end end end