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.
80 81 82 83 84 85 86 87 |
# File 'lib/newsman/issues.rb', line 80 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.
78 79 80 |
# File 'lib/newsman/issues.rb', line 78 def repo @repo end |
Instance Method Details
#detailed_title ⇒ Object
112 113 114 |
# File 'lib/newsman/issues.rb', line 112 def detailed_title "title: #{@title}, repo: #{@repo}, issue number: \##{@number}, url: #{url}, labels: #{labels}" end |
#extract_real_body ⇒ Object
89 90 91 92 93 94 |
# File 'lib/newsman/issues.rb', line 89 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
126 127 128 |
# File 'lib/newsman/issues.rb', line 126 def important? labels.include? 'soon' end |
#issue_link ⇒ Object
96 97 98 99 100 |
# File 'lib/newsman/issues.rb', line 96 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
134 135 136 |
# File 'lib/newsman/issues.rb', line 134 def labels @additional[:labels] end |
#to_json(*_args) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/newsman/issues.rb', line 116 def to_json(*_args) { number: @number, title: @title, description: @body, repository: @repo, url: url.to_s }.to_json end |
#to_s ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/newsman/issues.rb', line 102 def to_s <<~MARKDOWN title: ```#{@title}```, description: ```#{extract_real_body}```, repo: ```#{@repo}```, issue number: \##{@number}, additional: #{@additional} MARKDOWN end |
#url ⇒ Object
130 131 132 |
# File 'lib/newsman/issues.rb', line 130 def url @additional[:url] end |