module Abstractor::Methods::Models::AbstractorAbstraction::InstanceMethods
Public Instance Methods
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.
@param [Abstractor::AbstractorAbstractionSource] abstractor_abstraction_source An instance of Abstractor::AbstractorAbstractionSource
to check for the presence of an Abstractor::AbstractorIndirectSource. @return [Abstractor::AbstractorIndirectSource, nil]
# 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
# 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
# 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
# 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 suggestions on the abstraction with a suggestion status of ‘needs review’ that are not present in the array of hashes representing suggestions passed in.
@param [Array<Hash>] suggestions @return [void]
# 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
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
# 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
Determines if the abstraction has been reviewed.
@return [Boolean]
# File lib/abstractor/methods/models/abstractor_abstraction.rb, line 94 def unreviewed? (value.blank? && unknown.blank? && not_applicable.blank?) end
Returns all the suggestions for the abstraction with a suggestion status of ‘needs review’
@return [ActiveRecord::Relation] List of [Abstractor::AbstractorSuggestion].
# 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