Class: PddIssue
- Inherits:
-
Object
- Object
- PddIssue
- Defined in:
- lib/newsman/issues.rb
Overview
This class represents a GitHub issue abstraction created by a 0pdd robot.
Instance Attribute Summary collapse
-
#repo ⇒ Object
Returns the value of attribute repo.
Instance Method Summary collapse
- #detailed_title ⇒ Object
- #extract_real_body ⇒ Object
- #important? ⇒ Boolean
-
#initialize(title, body, repo, number, **additional) ⇒ PddIssue
constructor
A new instance of PddIssue.
- #issue_link ⇒ Object
- #labels ⇒ Object
- #to_json(*_args) ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(title, body, repo, number, **additional) ⇒ PddIssue
Returns a new instance of PddIssue.
82 83 84 85 86 87 88 89 |
# File 'lib/newsman/issues.rb', line 82 def initialize(title, body, repo, number, **additional) defaults = { url: 'undefined', labels: [] } @title = title @body = body @repo = repo @number = number @additional = defaults.merge(additional) end |
Instance Attribute Details
#repo ⇒ Object
Returns the value of attribute repo.
80 81 82 |
# File 'lib/newsman/issues.rb', line 80 def repo @repo end |
Instance Method Details
#detailed_title ⇒ Object
114 115 116 |
# File 'lib/newsman/issues.rb', line 114 def detailed_title "title: #{@title}, repo: #{@repo}, issue number: \##{@number}, url: #{url}, labels: #{labels}" end |
#extract_real_body ⇒ Object
91 92 93 94 95 96 |
# File 'lib/newsman/issues.rb', line 91 def extract_real_body address = issue_link line_numbers = address.scan(/#L(\d+)-L(\d+)/).flatten.map(&:to_i) uri = URI(address) Net::HTTP.get(uri).lines[line_numbers[0] - 1..line_numbers[1]] end |
#important? ⇒ Boolean
128 129 130 |
# File 'lib/newsman/issues.rb', line 128 def important? labels.include? IMPORTANT_ISSUE end |
#issue_link ⇒ Object
98 99 100 101 102 |
# File 'lib/newsman/issues.rb', line 98 def issue_link @body[%r{https://github\.com/[\w\-/]+/blob/[\w\d]+/[\w/.-]+#\w+-\w+}, 0] .gsub('https://github.com', 'https://raw.githubusercontent.com') .gsub('blob/', '') end |
#labels ⇒ Object
136 137 138 |
# File 'lib/newsman/issues.rb', line 136 def labels @additional[:labels] end |
#to_json(*_args) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/newsman/issues.rb', line 118 def to_json(*_args) { number: @number, title: @title, description: @body, repository: @repo, url: url.to_s }.to_json end |
#to_s ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/newsman/issues.rb', line 104 def to_s <<~MARKDOWN title: ```#{@title}```, description: ```#{extract_real_body}```, repo: ```#{@repo}```, issue number: \##{@number}, additional: #{@additional} MARKDOWN end |
#url ⇒ Object
132 133 134 |
# File 'lib/newsman/issues.rb', line 132 def url @additional[:url] end |