class ReadmeScore::Document::Score
Constants
- SCORE_METRICS
Attributes
metrics[RW]
Public Class Methods
new(metrics)
click to toggle source
# File lib/readme-score/document/score.rb, line 52 def initialize(metrics) @metrics = metrics end
Public Instance Methods
human_breakdown()
click to toggle source
# File lib/readme-score/document/score.rb, line 82 def human_breakdown score_breakdown(true) end
inspect()
click to toggle source
# File lib/readme-score/document/score.rb, line 99 def inspect "#<#{self.class} - #{total_score}>" end
score_breakdown(as_description = false)
click to toggle source
# File lib/readme-score/document/score.rb, line 56 def score_breakdown(as_description = false) breakdown = {} SCORE_METRICS.each { |h| metric_option = OpenStruct.new(h) metric_name = metric_option.metric_name || metric_option.metric metric_score_value = 0 # points for each occurance if metric_option.value_per metric_score_value = [metrics.send(metric_option.metric) * metric_option.value_per, metric_option.max].min elsif metric_option.if_less_than if metrics.send(metric_option.metric) < metric_option.if_less_than metric_score_value = metric_option.value end else metric_score_value = metrics.send(metric_option.metric) ? metric_option.value : 0 end if as_description breakdown[metric_option.description] = [metric_score_value, metric_option.max || metric_option.value] else breakdown[metric_name] = metric_score_value end } breakdown end
Also aliased as: breakdown
to_f()
click to toggle source
# File lib/readme-score/document/score.rb, line 95 def to_f to_i.to_f end
total_score()
click to toggle source
# File lib/readme-score/document/score.rb, line 86 def total_score score = 0 score_breakdown.each {|metric, points| score += points.to_i } [[score, 100].min, 0].max end
Also aliased as: to_i