Class: ReadmeScore::Document::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/readme-score/document/metrics.rb

Constant Summary collapse

EQUATION_METRICS =
[
  :cumulative_code_block_length
]

Instance Method Summary collapse

Constructor Details

#initialize(noko_or_html) ⇒ Metrics

Returns a new instance of Metrics.



7
8
9
# File 'lib/readme-score/document/metrics.rb', line 7

def initialize(noko_or_html)
  @noko = Util.to_noko(noko_or_html)
end

Instance Method Details

#code_block_to_paragraph_ratioObject



31
32
33
34
35
36
# 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_lengthObject



11
12
13
# File 'lib/readme-score/document/metrics.rb', line 11

def cumulative_code_block_length
  all_code_blocks.inner_html.length
end

#has_gifs?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/readme-score/document/metrics.rb', line 62

def has_gifs?
  number_of_gifs > 0
end

#has_images?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/readme-score/document/metrics.rb', line 54

def has_images?
  number_of_images > 0
end

#has_lists?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/readme-score/document/metrics.rb', line 50

def has_lists?
  all_lists.length > 0
end

#has_tables?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/readme-score/document/metrics.rb', line 70

def has_tables?
  !all_tables.empty?
end

#inspectObject



74
75
76
# File 'lib/readme-score/document/metrics.rb', line 74

def inspect
  "#<#{self.class}>"
end

#number_of_code_blocksObject



19
20
21
# File 'lib/readme-score/document/metrics.rb', line 19

def number_of_code_blocks
  all_code_blocks.length
end


44
45
46
47
48
# File 'lib/readme-score/document/metrics.rb', line 44

def number_of_external_links
  all_links.reject {|a|
    internal_link?(a)
  }.count
end

#number_of_gifsObject



66
67
68
# File 'lib/readme-score/document/metrics.rb', line 66

def number_of_gifs
  all_gifs.length
end

#number_of_imagesObject



58
59
60
# File 'lib/readme-score/document/metrics.rb', line 58

def number_of_images
  all_images.count
end


38
39
40
41
42
# File 'lib/readme-score/document/metrics.rb', line 38

def number_of_internal_links
  all_links.select {|a|
    internal_link?(a)
  }.count
end


15
16
17
# File 'lib/readme-score/document/metrics.rb', line 15

def number_of_links
  all_links.length
end

#number_of_non_code_sectionsObject



27
28
29
# File 'lib/readme-score/document/metrics.rb', line 27

def number_of_non_code_sections
  (all_paragraphs + all_lists).length
end

#number_of_paragraphsObject



23
24
25
# File 'lib/readme-score/document/metrics.rb', line 23

def number_of_paragraphs
  all_paragraphs.length
end