class ReadmeScore::Document::Metrics

Constants

EQUATION_METRICS

Public Class Methods

new(noko_or_html) click to toggle source
# File lib/readme-score/document/metrics.rb, line 7
def initialize(noko_or_html)
  @noko = Util.to_noko(noko_or_html)
end

Public Instance Methods

code_block_to_paragraph_ratio() click to toggle source
# File lib/readme-score/document/metrics.rb, line 31
def code_block_to_paragraph_ratio
  if number_of_paragraphs.to_f == 0.0
    return 0
  end
  number_of_code_blocks.to_f / number_of_paragraphs.to_f
end
cumulative_code_block_length() click to toggle source
# File lib/readme-score/document/metrics.rb, line 11
def cumulative_code_block_length
  all_code_blocks.inner_html.length
end
has_gifs?() click to toggle source
# File lib/readme-score/document/metrics.rb, line 62
def has_gifs?
  number_of_gifs > 0
end
has_images?() click to toggle source
# File lib/readme-score/document/metrics.rb, line 54
def has_images?
  number_of_images > 0
end
has_lists?() click to toggle source
# File lib/readme-score/document/metrics.rb, line 50
def has_lists?
  all_lists.length > 0
end
has_tables?() click to toggle source
# File lib/readme-score/document/metrics.rb, line 70
def has_tables?
  !all_tables.empty?
end
inspect() click to toggle source
# File lib/readme-score/document/metrics.rb, line 74
def inspect
  "#<#{self.class}>"
end
number_of_code_blocks() click to toggle source
# File lib/readme-score/document/metrics.rb, line 19
def number_of_code_blocks
  all_code_blocks.length
end
number_of_gifs() click to toggle source
# File lib/readme-score/document/metrics.rb, line 66
def number_of_gifs
  all_gifs.length
end
number_of_images() click to toggle source
# File lib/readme-score/document/metrics.rb, line 58
def number_of_images
  all_images.count
end
number_of_non_code_sections() click to toggle source
# File lib/readme-score/document/metrics.rb, line 27
def number_of_non_code_sections
  (all_paragraphs + all_lists).length
end
number_of_paragraphs() click to toggle source
# File lib/readme-score/document/metrics.rb, line 23
def number_of_paragraphs
  all_paragraphs.length
end

Private Instance Methods

all_code_blocks() click to toggle source
# File lib/readme-score/document/metrics.rb, line 83
def all_code_blocks
  @noko.search('pre')
end
all_gifs() click to toggle source
# File lib/readme-score/document/metrics.rb, line 99
def all_gifs
  all_images.select {|a|
    source_attributes = ['src', 'data-canonical-src']
    source_attributes.map {|_attr|
      a[_attr] && a[_attr].downcase.include?(".gif")
    }.any?
  }
end
all_images() click to toggle source
# File lib/readme-score/document/metrics.rb, line 95
def all_images
  @noko.search('img')
end
all_lists() click to toggle source
# File lib/readme-score/document/metrics.rb, line 91
def all_lists
  @noko.search('ol') + @noko.search('ul')
end
all_paragraphs() click to toggle source
# File lib/readme-score/document/metrics.rb, line 87
def all_paragraphs
  @noko.search('p')
end
all_tables() click to toggle source
# File lib/readme-score/document/metrics.rb, line 108
def all_tables
  @noko.search('table')
end