Module: Superset::Display
- Included in:
- Request
- Defined in:
- lib/superset/display.rb
Instance Method Summary collapse
- #ids ⇒ Object
- #list ⇒ Object
- #list_attributes ⇒ Object
- #result ⇒ Object
- #rows ⇒ Object
- #table ⇒ Object
- #title ⇒ Object
- #to_h ⇒ Object
Instance Method Details
#ids ⇒ Object
35 36 37 |
# File 'lib/superset/display.rb', line 35 def ids result.map { |d| d[:id] } end |
#list ⇒ Object
3 4 5 |
# File 'lib/superset/display.rb', line 3 def list puts table.to_s end |
#list_attributes ⇒ Object
43 44 45 |
# File 'lib/superset/display.rb', line 43 def list_attributes raise NotImplementedError.new("You must implement list_attributes.") end |
#result ⇒ Object
47 48 49 |
# File 'lib/superset/display.rb', line 47 def result raise NotImplementedError.new("You must implement result.") end |
#rows ⇒ Object
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 |
#table ⇒ Object
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 |
#title ⇒ Object
39 40 41 |
# File 'lib/superset/display.rb', line 39 def title self.class.to_s end |
#to_h ⇒ Object
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 |