Class: Zend::Command::Ticket::List

Inherits:
Base
  • Object
show all
Defined in:
lib/zend/command/ticket/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api, #is_num?, #terminal_width, #truncate

Constructor Details

#initialize(query, options) ⇒ List

Returns a new instance of List.



6
7
8
9
10
11
12
13
14
15
# 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

Instance Attribute Details

#closedObject (readonly)

Returns the value of attribute closed.



4
5
6
# File 'lib/zend/command/ticket/list.rb', line 4

def closed
  @closed
end

#newObject (readonly)

Returns the value of attribute new.



4
5
6
# File 'lib/zend/command/ticket/list.rb', line 4

def new
  @new
end

#openObject (readonly)

Returns the value of attribute open.



4
5
6
# File 'lib/zend/command/ticket/list.rb', line 4

def open
  @open
end

#pendingObject (readonly)

Returns the value of attribute pending.



4
5
6
# File 'lib/zend/command/ticket/list.rb', line 4

def pending
  @pending
end

#solvedObject (readonly)

Returns the value of attribute solved.



4
5
6
# File 'lib/zend/command/ticket/list.rb', line 4

def solved
  @solved
end

Instance Method Details

#all?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/zend/command/ticket/list.rb', line 52

def all?
  ! [@new, @open, @pending, @solved, @closed].any?
end

#col_id(ticket) ⇒ Object



37
38
39
# File 'lib/zend/command/ticket/list.rb', line 37

def col_id(ticket)

end

#col_subject(subject) ⇒ Object



33
34
35
# File 'lib/zend/command/ticket/list.rb', line 33

def col_subject(subject)
  truncate(subject, terminal_width - 30)
end

#queryObject



64
65
66
# File 'lib/zend/command/ticket/list.rb', line 64

def query
  @query
end

#query_stringObject



56
57
58
59
60
61
62
# 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_commandObject



23
24
25
26
27
28
29
30
31
# 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

#statusObject



68
69
70
71
72
73
74
75
76
77
78
79
# 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

#tableObject



41
42
43
44
45
46
47
48
49
50
# 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_dataObject



17
18
19
20
21
# 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