Class: ForkReadme::Generator

Inherits:
Object
  • Object
show all
Includes:
URI::REGEXP::PATTERN
Defined in:
lib/forkreadme/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Generator



11
12
13
14
15
16
17
# File 'lib/forkreadme/generator.rb', line 11

def initialize path
  @path = path

  repo_name = github_repo_name @path
  @repo = octokit.repo repo_name
  @parent = parent_of @repo
end

Instance Method Details

#introObject

Public: Returns the introduction paragraph.



24
25
26
27
# File 'lib/forkreadme/generator.rb', line 24

def intro
  link = link_to(@parent.name, @parent.html_url)
  "This is a fork of #{link}, with pull requests:"
end

Public: Generate a paragraph summarizing the pull requests.

with_images - Include pullstat.us images?

Returns the paragraph as Markdown.



34
35
36
37
38
39
40
41
# File 'lib/forkreadme/generator.rb', line 34

def links with_images
  pull_requests(@parent).select do |pull|
    @repo.id == (pull.head.repo && pull.head.repo.id)

  end.map do |pull|
    "* " + line_for(pull, with_images)
  end
end

#readme(with_images = false) ⇒ Object



19
20
21
# File 'lib/forkreadme/generator.rb', line 19

def readme with_images=false
  intro + "\n\n" + (links(with_images).join "\n")
end