Class: GitHubRecordsArchiver::Issue
- Inherits:
-
Object
- Object
- GitHubRecordsArchiver::Issue
show all
- Includes:
- DataHelper
- Defined in:
- lib/github_records_archiver/issue.rb
Constant Summary
collapse
- KEYS =
i[title number state html_url created_at closed_at].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DataHelper
#method_missing, #respond_to_missing?, #to_h, #to_json
Constructor Details
#initialize(repository: nil, number: nil) ⇒ Issue
Returns a new instance of Issue.
10
11
12
13
14
|
# File 'lib/github_records_archiver/issue.rb', line 10
def initialize(repository: nil, number: nil)
repository = Repository.new(repository) if repository.is_a? String
@repository = repository
@number = number
end
|
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
4
5
6
|
# File 'lib/github_records_archiver/issue.rb', line 4
def number
@number
end
|
#repository ⇒ Object
Returns the value of attribute repository.
3
4
5
|
# File 'lib/github_records_archiver/issue.rb', line 3
def repository
@repository
end
|
Class Method Details
.from_hash(repo, hash) ⇒ Object
16
17
18
19
20
|
# File 'lib/github_records_archiver/issue.rb', line 16
def self.from_hash(repo, hash)
issue = Issue.new(repository: repo, number: hash[:number])
issue.instance_variable_set('@data', hash.to_h)
issue
end
|
Instance Method Details
#archive ⇒ Object
46
47
48
49
|
# File 'lib/github_records_archiver/issue.rb', line 46
def archive
File.write(path('md'), to_s)
File.write(path('json'), to_json)
end
|
#as_json ⇒ Object
42
43
44
|
# File 'lib/github_records_archiver/issue.rb', line 42
def as_json
data.to_h.merge('comments' => .map(&:as_json))
end
|
26
27
28
29
30
31
32
33
|
# File 'lib/github_records_archiver/issue.rb', line 26
def
||= begin
return [] if data[:comments].nil? || data[:comments].zero?
client = GitHubRecordsArchiver.client
= client. repository.full_name, number
.map { |hash| .from_hash(repository, hash) }
end
end
|
#data ⇒ Object
22
23
24
|
# File 'lib/github_records_archiver/issue.rb', line 22
def data
@data ||= GitHubRecordsArchiver.client.issue repository.name, number
end
|
#to_s ⇒ Object
35
36
37
38
39
40
|
# File 'lib/github_records_archiver/issue.rb', line 35
def to_s
md = meta_for_markdown.to_yaml + "---\n\n# #{title}\n\n"
md << body unless body.to_s.empty?
md << unless .nil?
md
end
|