Class: CommentUtil

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

Overview

code to communicate with your backend goes hereā€¦

Instance Method Summary collapse

Constructor Details

#initialize(ticket_id, trac, doc = nil) ⇒ CommentUtil

Returns a new instance of CommentUtil.



5
6
7
8
# File 'lib/trac/trac.rb', line 5

def initialize(ticket_id, trac, doc = nil)
  @doc = doc || Nokogiri::HTML(open("#{trac[:url]}/ticket/#{ticket_id}", :http_basic_authentication=>[trac[:username], trac[:password]]))
  @ticket_id = ticket_id
end

Instance Method Details

#commentsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/trac/trac.rb', line 10

def comments
  comment_id = 0
  @doc.css('h3.change a.timeline').collect do |value|
    body = @doc.css('div.comment')
    authors = @doc.css('h3.change')
    comment_id += 1
    unless body[comment_id-1].nil? || authors[comment_id-1].nil?
      comment_body = body[comment_id-1].text
      if comment_body =~ /\w+/
        build_comment_hash(value, comment_id, comment_body, authors[comment_id-1].content)
      end
    end
  end
end