Class: GitHubRecordsArchiver::Comment

Inherits:
Object
  • Object
show all
Includes:
DataHelper
Defined in:
lib/github_records_archiver/comment.rb

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(repo, id) ⇒ Comment

Returns a new instance of Comment.



8
9
10
11
12
# File 'lib/github_records_archiver/comment.rb', line 8

def initialize(repo, id)
  repo = Repository.new(repo) if repo.is_a? String
  @repository = repo
  @id = id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GitHubRecordsArchiver::DataHelper

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/github_records_archiver/comment.rb', line 4

def id
  @id
end

#repositoryObject (readonly)

Returns the value of attribute repository.



3
4
5
# File 'lib/github_records_archiver/comment.rb', line 3

def repository
  @repository
end

Class Method Details

.from_hash(repo, hash) ⇒ Object



14
15
16
17
18
# File 'lib/github_records_archiver/comment.rb', line 14

def self.from_hash(repo, hash)
  comment = Comment.new(repo, hash[:number])
  comment.instance_variable_set '@data', hash.to_h
  comment
end

Instance Method Details

#dataObject



20
21
22
23
24
# File 'lib/github_records_archiver/comment.rb', line 20

def data
  @data ||= begin
    GitHubRecordsArchiver.client.issue_comment(repository.full_name, id)
  end
end

#to_sObject



26
27
28
29
30
# File 'lib/github_records_archiver/comment.rb', line 26

def to_s
  output = "@#{user[:login]} at #{created_at} wrote:\n\n"
  output << body
  output
end