Class: TicketMaster::Provider::Trac::Comment

Inherits:
Base::Comment
  • Object
show all
Defined in:
lib/provider/comment.rb

Overview

The comment class for ticketmaster-yoursystem

Do any mapping between Ticketmaster and your system’s comment model here versions of the ticket.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Comment

declare needed overloaded methods here



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/provider/comment.rb', line 11

def initialize(*object)
  if object.first
    object = object.first
    unless object.is_a? Hash
      @system_data = {:client => object}
      hash = {:id => object[:id],
        :author => object.author,
        :body => object.body,
        :ticket_id => object.ticket_id,
        :created_at => object.created_at,
        :updated_at => object.updated_at}
    else
      hash = object
    end
    super(hash)
  end
end

Class Method Details

.find(project_id, ticket_id, *options) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/provider/comment.rb', line 54

def self.find(project_id, ticket_id, *options)
  if options[0].first.is_a? Array
    self.find_all(ticket_id).select do |comment|
      comment if options[0].any? { |id| id == comment.id }
    end
  elsif options[0].first.is_a? Hash
    self.find_by_attributes(project_id, ticket_id, options[0].first)
  else
    self.find_all(ticket_id)
  end
end

.find_all(ticket_id) ⇒ Object



70
71
72
73
74
75
# File 'lib/provider/comment.rb', line 70

def self.find_all(ticket_id)
  comments = CommentUtil.new(ticket_id,TicketMaster::Provider::Trac.api).comments
  comments.compact.collect do |comment| 
    TicketMaster::Provider::Trac::Comment.new comment 
  end
end

.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object



49
50
51
52
# File 'lib/provider/comment.rb', line 49

def self.find_by_attributes(project_id, ticket_id, attributes = {})
  comments = self.find_all(ticket_id)
  search_by_attribute(comments, attributes)
end

.find_by_id(project_id, ticket_id, id) ⇒ Object



66
67
68
# File 'lib/provider/comment.rb', line 66

def self.find_by_id(project_id, ticket_id, id)
  self.find_all(ticket_id).select { |comment| comment[:id] == id }.first
end

Instance Method Details

#created_atObject



29
30
31
32
33
34
35
# File 'lib/provider/comment.rb', line 29

def created_at
  begin
    Time.parse(self[:created_at])
  rescue
    self[:created_at]
  end
end

#idObject



45
46
47
# File 'lib/provider/comment.rb', line 45

def id
  self[:id]
end

#updated_atObject



37
38
39
40
41
42
43
# File 'lib/provider/comment.rb', line 37

def updated_at
  begin
    Time.parse(self[:updated_at])
  rescue
    self[:updated_at]
  end
end