Module: Abstractor::Methods::Models::AbstractorAbstraction::InstanceMethods

Included in:
AbstractorAbstraction
Defined in:
lib/abstractor/methods/models/abstractor_abstraction.rb

Instance Method Summary collapse

Instance Method Details

#detect_abstractor_indirect_source(abstractor_abstraction_source) ⇒ Abstractor::AbstractorIndirectSource?

Detects if the abstraction already has an Abstractor::AbstractorIndirectSource based on the Abstractor::AbstractorAbstractionSource passed via the abstractor_abstraction_source parameter. Retuns it if present. Otherwise nil.

Parameters:

  • abstractor_abstraction_source (Abstractor::AbstractorAbstractionSource)

    An instance of Abstractor::AbstractorAbstractionSource to check for the presence of an Abstractor::AbstractorIndirectSource.

Returns:



104
105
106
107
108
109
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 104

def detect_abstractor_indirect_source(abstractor_abstraction_source)
  abstractor_indirect_source = nil
  abstractor_indirect_source = abstractor_indirect_sources(true).detect do |ais|
    ais.abstractor_abstraction_source == abstractor_abstraction_source
  end
end

#detect_abstractor_suggestion(suggested_value, unknown, not_applicable) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 81

def detect_abstractor_suggestion(suggested_value, unknown, not_applicable)
  abstractor_suggestion = nil
  abstractor_suggestion = abstractor_suggestions(true).detect do |abstractor_suggestion|
    abstractor_suggestion.suggested_value == suggested_value &&
    abstractor_suggestion.unknown == unknown &&
    abstractor_suggestion.not_applicable == not_applicable
  end
end

#display_valueObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 69

def display_value
  if unknown
    'unknown'
  elsif not_applicable
    'not applicable'
  elsif value.blank?
    '[Not set]'
  else
    value
  end
end

#matching_abstractor_suggestionsObject



62
63
64
65
66
67
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 62

def matching_abstractor_suggestions
  unknown_values        = unknown ? unknown : [unknown, nil]
  not_applicable_values = not_applicable ? not_applicable : [not_applicable, nil]
  suggested_values = value.blank? ? ['', nil] : value
  abstractor_suggestions.where(unknown: unknown_values, not_applicable: not_applicable_values, suggested_value: suggested_values)
end

#remove_unreviewed_suggestions_not_matching_suggestions(suggestions) ⇒ void

This method returns an undefined value.

Remove suggestions on the abstraction with a suggestion status of ‘needs review’ that are not present in the array of hashes representing suggestions passed in.

Parameters:

  • suggestions (Array<Hash>)


124
125
126
127
128
129
130
131
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 124

def remove_unreviewed_suggestions_not_matching_suggestions(suggestions)
  unreviewed_abstractor_suggestions.each do |abstractor_suggestion|
    not_detritus = suggestions.detect { |suggestion| suggestion[:suggestion] == abstractor_suggestion.suggested_value }
    unless not_detritus
      abstractor_suggestion.destroy
    end
  end
end

#review_suggestionsObject

Updates status of suggestions linked to the abstraction accepts suggestions with matching values. This effectively rejects the rest of the suggestions. If suggestions with matching values do not exist, rejects all suggestions



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 40

def review_suggestions
  accepted_status = Abstractor::AbstractorSuggestionStatus.where(name: Abstractor::Enum::ABSTRACTOR_SUGGESTION_STATUS_ACCEPTED).first
  rejected_status = Abstractor::AbstractorSuggestionStatus.where(name: Abstractor::Enum::ABSTRACTOR_SUGGESTION_STATUS_REJECTED).first

  unless unreviewed?
    matching_suggestions = matching_abstractor_suggestions
    if matching_suggestions.any?
      matching_suggestions.each do |abstractor_suggestion|
        abstractor_suggestion.abstractor_suggestion_status = accepted_status
        abstractor_suggestion.save!
      end
    else
      abstractor_suggestions.each do |abstractor_suggestion|
        unless abstractor_suggestion.abstractor_suggestion_status == rejected_status
          abstractor_suggestion.abstractor_suggestion_status = rejected_status
          abstractor_suggestion.save!
        end
      end
    end
  end
end

#unreviewed?Boolean

Determines if the abstraction has been reviewed.

Returns:

  • (Boolean)


94
95
96
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 94

def unreviewed?
  (value.blank? && unknown.blank? && not_applicable.blank?)
end

#unreviewed_abstractor_suggestionsActiveRecord::Relation

Returns all the suggestions for the abstraction with a suggestion status of ‘needs review’

Returns:

  • (ActiveRecord::Relation)

    List of [Abstractor::AbstractorSuggestion].



115
116
117
# File 'lib/abstractor/methods/models/abstractor_abstraction.rb', line 115

def unreviewed_abstractor_suggestions
  abstractor_suggestions.select { |abstractor_suggestion| abstractor_suggestion.abstractor_suggestion_status.name == Abstractor::Enum::ABSTRACTOR_SUGGESTION_STATUS_NEEDS_REVIEW }
end