Module: Superset::Display

Included in:
Request
Defined in:
lib/superset/display.rb

Instance Method Summary collapse

Instance Method Details

#idsObject



35
36
37
# File 'lib/superset/display.rb', line 35

def ids
  result.map { |d| d[:id] }
end

#listObject



3
4
5
# File 'lib/superset/display.rb', line 3

def list
  puts table.to_s
end

#list_attributesObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/superset/display.rb', line 43

def list_attributes
  raise NotImplementedError.new("You must implement list_attributes.")
end

#resultObject

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/superset/display.rb', line 47

def result
  raise NotImplementedError.new("You must implement result.")
end

#rowsObject



15
16
17
18
19
20
21
22
23
# File 'lib/superset/display.rb', line 15

def rows
  if result.is_a?(Hash)
    list_attributes.map { |la| result[la].to_s }
  else
    result.map do |d|
      list_attributes.map { |la| d[la].to_s }
    end
  end
end

#tableObject



7
8
9
10
11
12
13
# File 'lib/superset/display.rb', line 7

def table
  Terminal::Table.new(
    title: title,
    headings: list_attributes.map(&:to_s).map(&:humanize),
    rows: rows
  )
end

#titleObject



39
40
41
# File 'lib/superset/display.rb', line 39

def title
  self.class.to_s
end

#to_hObject



25
26
27
28
29
30
31
32
33
# File 'lib/superset/display.rb', line 25

def to_h
  if result.is_a?(Hash)
    list_attributes.to_h { |la| [la, result[la]] }
  else
    result.map do |d|
      list_attributes.to_h { |la| [la, d[la]] }
    end
  end
end