Sha256: 0b0f1477806bc9c9beb123310174006fd56d23470e377af236d152cacc491ee6

Contents?: true

Size: 924 Bytes

Versions: 94

Compression:

Stored size: 924 Bytes

Contents

module Feedback
  class Resource < ApplicationRecord
    has_many :feedbacks, dependent: :destroy

    before_validation :set_product
    validates :uri, presence: true, allow_blank: false

    def display_name
      uri
    end

    def score
      if feedbacks.any?
        score_value.round(1)
      else
        'n/a'
      end
    end

    def score_value
      ((feedbacks.positive.count / feedbacks.count.to_f) * 100.to_f)
    end

    def relative_link
      URI(uri).path
    end

    def self.worst_performing
      all.select { |resource| resource.feedbacks.count > 5 }.sort_by(&:score_value)
    end

    def self.best_performing
      worst_performing.reverse
    end

    private

    def set_product
      products = DocumentationConstraint.product_with_parent_list
      self.product = products.detect do |product|
        break product if URI(uri).path.start_with? "/#{product}"
      end
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.15 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.14 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.13 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.12 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.11 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.10 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.9 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.8 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.7 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.6 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.5 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.4 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.3 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.2 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.1 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.5.0 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.4.9 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.4.8 lib/nexmo_developer/app/models/feedback/resource.rb
station-0.4.7 lib/nexmo_developer/app/models/feedback/resource.rb