Class: Nexpose::Ticket::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/ticket.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, author, created) ⇒ Event

Returns a new instance of Event.



235
236
237
238
239
# File 'lib/nexpose/ticket.rb', line 235

def initialize(state, author, created)
  @state   = state
  @author  = author
  @created = created
end

Instance Attribute Details

#authorObject (readonly)

The login name of the person responsible for the event.



227
228
229
# File 'lib/nexpose/ticket.rb', line 227

def author
  @author
end

#commentObject

Comment on the ticket event.



233
234
235
# File 'lib/nexpose/ticket.rb', line 233

def comment
  @comment
end

#created_onObject (readonly)

Date and time of the ticket event.



225
226
227
# File 'lib/nexpose/ticket.rb', line 225

def created_on
  @created_on
end

#descriptionObject

Description of the ticket event.



231
232
233
# File 'lib/nexpose/ticket.rb', line 231

def description
  @description
end

#stateObject (readonly)

The status of the ticket at the time the event was recorded.



229
230
231
# File 'lib/nexpose/ticket.rb', line 229

def state
  @state
end

Class Method Details

.parse(xml) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/nexpose/ticket.rb', line 241

def self.parse(xml)
  author        = xml.attributes['author']
  created_on    = DateTime.parse(xml.attributes['created-on']).to_time
  created_on -= created_on.gmt_offset

  event         = REXML::XPath.first(xml, 'Event')
  lookup        = Ticket::State.constants.reduce({}) { |a, e| a[Ticket::State.const_get(e)] = e; a }
  state         = lookup[event.attributes['state']]
  desc          = event.text

  event         = new(state, author, created_on)

  comment       = REXML::XPath.first(xml, 'Comment')
  event.comment = comment.text if comment

  event.description = desc if desc
  event
end