Class: Readme

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/readme.rb

Instance Method Summary collapse

Instance Method Details

#check_unmaintainedObject



17
18
19
20
21
22
23
# File 'app/models/readme.rb', line 17

def check_unmaintained
  return unless unmaintained?
  github_repository.update_attribute(:status, 'Unmaintained')
  github_repository.projects.each do |project|
    project.update_attribute(:status, 'Unmaintained')
  end
end

#plain_textObject



13
14
15
# File 'app/models/readme.rb', line 13

def plain_text
  @plain_text ||= Nokogiri::HTML(html_body).text
end

#reformatObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/readme.rb', line 29

def reformat
  doc = Nokogiri::HTML(html_body)
  doc.xpath('//a').each do |d|
    rel_url = d.get_attribute('href')
    begin
      if rel_url.present? && !rel_url.match(/^#/) && URI.parse(rel_url)
        d.set_attribute('href', URI.join(github_repository.blob_url, rel_url))
      end
    rescue NoMethodError, URI::InvalidURIError, URI::InvalidComponentError
    end
  end
  doc.xpath('//img').each do |d|
    rel_url = d.get_attribute('src')

    begin
      if rel_url.present? && URI.parse(rel_url)
        d.set_attribute('src', URI.join(github_repository.raw_url, rel_url))
      end
    rescue NoMethodError, URI::InvalidURIError, URI::InvalidComponentError
    end
  end
  self.html_body = doc.to_s
end

#to_sObject



9
10
11
# File 'app/models/readme.rb', line 9

def to_s
  html_body
end

#unmaintained?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/readme.rb', line 25

def unmaintained?
  html_body.downcase.gsub("\n", '').include?('unmaintained.tech/badge.svg')
end