Module: Rawbotz::CLI::OrderResultTable

Defined in:
lib/rawbotz/cli/order_result_table.rb

Class Method Summary collapse

Class Method Details

.tables(diffs) ⇒ Object



3
4
5
6
7
8
9
10
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rawbotz/cli/order_result_table.rb', line 3

def self.tables diffs
  out = ""
  if !diffs[:error].empty?
    error_items = diffs[:error].map do |p|
      [p[0][0..35]]
    end
    out << Terminal::Table.new(title: "With error",
      headings: ['Product'],
      rows:     error_items,
      style:    {width: 60}).to_s
    out << "\n\n"
  end

  if !diffs[:perfect].empty?
    perfect_items = diffs[:perfect].map do |p, q|
      [p.local_product.remote_product.name[0..35], q]
    end
    out << Terminal::Table.new(title: "Perfect",
      headings: ['Product', 'In Cart'],
      rows:     perfect_items,
      style:    {width: 60}).to_s
    out << "\n\n"
  end

  if !diffs[:modified].empty?
    modified_items = diffs[:modified].map do |p,q|
      [p.local_product.remote_product.name[0..35], p.num_wished, q]
    end
    out << Terminal::Table.new(title: "Modified",
      headings: ['Product', 'Wished', 'In Cart'],
      rows:     modified_items,
      style:    {width:60}).to_s
    out << "\n\n"
  end

  if !diffs[:miss].empty?
    missing_items = diffs[:miss].map do |p,q|
      [p.local_product.remote_product.name[0..35], q]
    end
    out << Terminal::Table.new(title: "Missing (?)",
      headings: ['Product', 'In Cart'],
      rows:     missing_items,
      style:    {width:60}).to_s
    out << "\n\n"
  end

  if !diffs[:under_avail].empty?
    under_avail_items = diffs[:under_avail].map do |p,q|
      [p.local_product.remote_product.name[0..35], p.num_wished, q]
    end
    out << Terminal::Table.new(title: "Not available as such",
      headings: ['Product', 'Wanted', 'In Cart'],
      rows:     under_avail_items,
      style:    {width:60}).to_s
    out << "\n\n"
  end

  if !diffs[:extra].empty?
    extra_items = diffs[:extra].map do |n,q|
      [n[0..35], q]
    end
    out << Terminal::Table.new(title: "Extra (not in rawbotz)",
      headings: ['Product', 'In Cart'],
      rows:     extra_items,
      style:    {width:60}).to_s
  end

  out
end