class Zend::Command::Ticket::List

Attributes

closed[R]
new[R]
open[R]
pending[R]
solved[R]

Public Class Methods

new(query, options) click to toggle source
# File lib/zend/command/ticket/list.rb, line 6
def initialize(query, options)
  @query    = query
  @new      = options['new']
  @open     = options['open']
  @pending  = options['pending']
  @solved   = options['solved']
  @closed   = options['closed']

  puts(table)
end

Public Instance Methods

all?() click to toggle source
# File lib/zend/command/ticket/list.rb, line 52
def all?
  ! [@new, @open, @pending, @solved, @closed].any?
end
col_id(ticket) click to toggle source
# File lib/zend/command/ticket/list.rb, line 37
def col_id(ticket)

end
col_subject(subject) click to toggle source
# File lib/zend/command/ticket/list.rb, line 33
def col_subject(subject)
  truncate(subject, terminal_width - 30)
end
query() click to toggle source
# File lib/zend/command/ticket/list.rb, line 64
def query
  @query
end
query_string() click to toggle source
# File lib/zend/command/ticket/list.rb, line 56
def query_string
  if is_num?(query)
    query
  else
    ['type:ticket', status, query].join(' ')
  end
end
search_command() click to toggle source
# File lib/zend/command/ticket/list.rb, line 23
def search_command
  # require 'pry'
  # binding.pry
  if query_string.strip == 'type:ticket'
    api.tickets.page((api.tickets.count/20).floor).per_page(20)
  else
    api.search(query: query_string)
  end
end
status() click to toggle source
# File lib/zend/command/ticket/list.rb, line 68
def status
  return '' if all?

  status = Array.new
  status << 'new'     if @new
  status << 'open'    if @open
  status << 'pending' if @pending
  status << 'solved'  if @solved
  status << 'closed'  if @closed

  status.map!{ |type| "status:#{type}" }.join(' ')
end
table() click to toggle source
# File lib/zend/command/ticket/list.rb, line 41
def table
  Terminal::Table.new(
    headings: %w[# Title Status],
    style: {
      width: terminal_width,
      padding_left: 2
    },
    rows: tabular_data
  )
end
tabular_data() click to toggle source
# File lib/zend/command/ticket/list.rb, line 17
def tabular_data
  search_command.fetch.each_with_object([]) do |ticket, arr|
    arr << [ticket.id, col_subject(ticket.subject), ticket.status]
  end
end