Class: ReadmeScore::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/readme-score/document.rb,
lib/readme-score/document/score.rb,
lib/readme-score/document/filter.rb,
lib/readme-score/document/loader.rb,
lib/readme-score/document/parser.rb,
lib/readme-score/document/metrics.rb,
lib/readme-score/document/loader/github_readme_finder.rb

Defined Under Namespace

Classes: Filter, Loader, Metrics, Parser, Score

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Document

Returns a new instance of Document.



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

def initialize(html)
  @html = html
  @noko = Nokogiri::HTML.fragment(@html)
  @metrics = Document::Metrics.new(html_for_analysis)
end

Instance Attribute Details

#filterObject

Returns the value of attribute filter.



9
10
11
# File 'lib/readme-score/document.rb', line 9

def filter
  @filter
end

#htmlObject

Returns the value of attribute html.



9
10
11
# File 'lib/readme-score/document.rb', line 9

def html
  @html
end

#metricsObject

Returns the value of attribute metrics.



9
10
11
# File 'lib/readme-score/document.rb', line 9

def metrics
  @metrics
end

Class Method Details

.load(url) ⇒ Object



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

def self.load(url)
  loader = Loader.new(url)
  loader.load!
  new(loader.html)
end

Instance Method Details

#html_for_analysisString

Returns HTML string ready for analysis.

Returns:

  • (String)

    HTML string ready for analysis



24
25
26
27
# File 'lib/readme-score/document.rb', line 24

def html_for_analysis
  @filter ||= Document::Filter.new(@noko)
  @filter.filtered_html!
end

#inspectObject



33
34
35
# File 'lib/readme-score/document.rb', line 33

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

#scoreObject



29
30
31
# File 'lib/readme-score/document.rb', line 29

def score
  @score ||= Score.new(metrics)
end