Class: SocialNetworking::Goal

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/social_networking/goal.rb

Overview

Something to be completed by a Participant.

Constant Summary collapse

ACTION_TYPES =

create a mini DSL for types of Goal actions

%w( created completed did_not_complete ).freeze
Actions =
Struct.new(*ACTION_TYPES.map(&:to_sym))
.new(*(ACTION_TYPES.map { |t| t.tr("_", " ") }))

Instance Method Summary collapse

Instance Method Details

#actionObject

rubocop:enable Style/PredicateName



54
55
56
57
58
59
60
61
62
# File 'app/models/social_networking/goal.rb', line 54

def action
  if is_completed
    "Completed"
  elsif due_on && due_on < Time.zone.today
    "Did Not Complete"
  else
    "Created"
  end
end

#is_completedObject

Necessary for legacy front-end code. rubocop:disable Style/PredicateName



42
43
44
# File 'app/models/social_networking/goal.rb', line 42

def is_completed
  completed_at?
end

#is_deletedObject

Necessary for legacy front-end code. rubocop:disable Style/PredicateName



49
50
51
# File 'app/models/social_networking/goal.rb', line 49

def is_deleted
  deleted_at?
end

#shared_descriptionObject



36
37
38
# File 'app/models/social_networking/goal.rb', line 36

def shared_description
  "Goal: #{description}"
end

#to_serializedObject



25
26
27
28
29
30
31
32
33
34
# File 'app/models/social_networking/goal.rb', line 25

def to_serialized
  if due_on
    {
      description: description,
      dueOn: due_on.to_s(:participant_date)
    }
  else
    {}
  end
end