Class: TicketAbstractorClient::Base::Attachment

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

Direct Known Subclasses

Jira::Attachment, ServiceNow::Attachment

Constant Summary collapse

SANITIZE_REGEXP =

Carrierwave uses the same regexp

/[^[:word:]\.\-\+]/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Attachment

Returns a new instance of Attachment.



37
38
39
40
41
42
43
# File 'lib/ticket_abstractor_client/base/attachment.rb', line 37

def initialize(opts)
  @file_path = opts[:file_path]
  @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

#communications_stackObject (readonly)

Returns the value of attribute communications_stack.



4
5
6
# File 'lib/ticket_abstractor_client/base/attachment.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/attachment.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/attachment.rb', line 4

def external_created_at
  @external_created_at
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

Class Method Details

.fetchObject



10
11
12
# File 'lib/ticket_abstractor_client/base/attachment.rb', line 10

def fetch
  method_not_implemented __method__
end

Instance Method Details

#set_data_hash!Object



49
50
51
52
53
54
# File 'lib/ticket_abstractor_client/base/attachment.rb', line 49

def set_data_hash!
  return if self.file_path.blank?
  file = File.new(self.file_path, 'rb')
  @data_hash = Digest::SHA512.hexdigest(file.read)
  file.close
end

#sync!Object



45
46
47
# File 'lib/ticket_abstractor_client/base/attachment.rb', line 45

def sync!
  self.class.method_not_implemented __method__
end

#to_hashObject



56
57
58
# File 'lib/ticket_abstractor_client/base/attachment.rb', line 56

def to_hash
  { file_path: @file_path, external_created_at: @external_created_at, data_hash: @data_hash }
end

#to_jsonObject



60
61
62
# File 'lib/ticket_abstractor_client/base/attachment.rb', line 60

def to_json
  self.to_hash.to_json
end