Class: TicketAbstractorClient::Base::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/ticket_abstractor_client/base/comment.rb

Direct Known Subclasses

Jira::Comment, ServiceNow::Comment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Comment

Returns a new instance of Comment.



10
11
12
13
14
15
16
17
18
# File 'lib/ticket_abstractor_client/base/comment.rb', line 10

def initialize(opts)
  opts = opts.with_indifferent_access
  @author = opts[:author]
  @body = opts.fetch(:body, nil) || raise(Errors::CommentArgumentError, 'Body is not given')
  @external_created_at = opts[:external_created_at]
  @data_hash = opts[:data_hash]
  @communications_stack = opts[:communications_stack] || []
  set_data_hash! if @data_hash.blank?
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



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

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#communications_stackObject (readonly)

Returns the value of attribute communications_stack.



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

def communications_stack
  @communications_stack
end

#data_hashObject (readonly)

Returns the value of attribute data_hash.



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

def data_hash
  @data_hash
end

#external_created_atObject (readonly)

Returns the value of attribute external_created_at.



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

def external_created_at
  @external_created_at
end

Class Method Details

.fetch(*opts) ⇒ Object



6
7
8
# File 'lib/ticket_abstractor_client/base/comment.rb', line 6

def self.fetch(*opts)
  method_not_implemented __method__
end

Instance Method Details

#set_data_hash!Object



20
21
22
23
# File 'lib/ticket_abstractor_client/base/comment.rb', line 20

def set_data_hash!
  content = "#{@external_created_at}:#{@author}:#{@body}"
  @data_hash = Digest::SHA512.hexdigest(content)
end

#sync!Object



25
26
27
# File 'lib/ticket_abstractor_client/base/comment.rb', line 25

def sync!
  self.class.method_not_implemented __method__
end

#to_hashObject



29
30
31
# File 'lib/ticket_abstractor_client/base/comment.rb', line 29

def to_hash
  { author: @author, body: @body, external_created_at: @external_created_at, data_hash: @data_hash }
end

#to_jsonObject



33
34
35
# File 'lib/ticket_abstractor_client/base/comment.rb', line 33

def to_json
  self.to_hash.to_json
end