Module: Roart::TicketPage
- Defined in:
- lib/roart/ticket_page.rb
Constant Summary collapse
- IntKeys =
%w[id]
- CUSTOM_FIELD_REGEXP =
/^(?!\s)(?:CF-([^:.]+)|CF\.\{([^}^:.]+)\}):(.*)$/.freeze
- REGULAR_FIELD_REGEXP =
/^(?!\s)([^:.]+):(.*)$/.freeze
Instance Method Summary collapse
- #to_hash ⇒ Object
-
#to_history_hash ⇒ Object
TODO: Don’t throw away attachments (/^ 13).
- #to_search_array ⇒ Object
- #to_search_list_array ⇒ Object
Instance Method Details
#to_hash ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/roart/ticket_page.rb', line 11 def to_hash hash = HashWithIndifferentAccess.new return false if self.size == 0 current_key = nil self.each do |line| case line when CUSTOM_FIELD_REGEXP data = $3 current_key = "cf_#{($1 || $2)}".gsub(/ /, '_') when REGULAR_FIELD_REGEXP data = $2 current_key = $1.strip.underscore else data = line end if current_key hash[current_key] ||= "" hash[current_key] << data << "\n" end end return false if hash.empty? # strip values hash.each { |k, v| hash[k].strip! if hash[k] } # id is integer hash["id"] = hash["id"].split("/").last.to_i hash end |
#to_history_hash ⇒ Object
TODO: Don’t throw away attachments (/^ 13)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/roart/ticket_page.rb', line 76 def to_history_hash hash = HashWithIndifferentAccess.new self.delete_if{|x| !x.include?(":") && !x.match(/^ {9}/) && !x.match(/^ {13}/)} self.each do |ln| if ln.match(/^ {9}/) && !ln.match(/^ {13}/) hash[:content] << "\n" + ln.strip if hash[:content] elsif ln.match(/^ {13}/) hash[:attachments] << "\n" + ln.strip if hash[:attachments] else ln = ln.split(":") unless ln.size == 1 || ln.first == 'Ticket' # we don't want to override the ticket method. key = ln.delete_at(0).strip.underscore value = ln.join(":").strip hash[key] = IntKeys.include?(key) ? value.to_i : value end end end hash end |
#to_search_array ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/roart/ticket_page.rb', line 57 def to_search_array array = Array.new self.delete_if{|x| !x.include?(":")} raise TicketNotFoundError, "No tickets matching search criteria found." if self.size == 0 self.each do |ln| hash = Hash.new ln = ln.split(":") id = ln.delete_at(0).strip.underscore sub = ln.join(":").strip hash[:id] = id.to_i hash[:subject] = sub hash[:full] = false hash[:history] = false array << hash end array end |
#to_search_list_array ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/roart/ticket_page.rb', line 47 def to_search_list_array array = Array.new self.each do |ticket| ticket.extend(Roart::TicketPage) ticket_hash = ticket.to_hash array << ticket_hash if ticket_hash end array end |