Class: Exrt::Cli::Renderer
- Inherits:
-
Object
- Object
- Exrt::Cli::Renderer
- Defined in:
- lib/exrt/cli/renderer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #header ⇒ Object
- #history_table_header ⇒ Object
-
#initialize(d:, t:) ⇒ Renderer
constructor
A new instance of Renderer.
- #is_history? ⇒ Boolean
- #is_latest? ⇒ Boolean
- #latest_table_header ⇒ Object
- #render ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(d:, t:) ⇒ Renderer
Returns a new instance of Renderer.
12 13 14 15 16 |
# File 'lib/exrt/cli/renderer.rb', line 12 def initialize(d:, t:) @data = d @type = t @table = TTY::Table.new header, rows end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/exrt/cli/renderer.rb', line 10 def data @data end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
10 11 12 |
# File 'lib/exrt/cli/renderer.rb', line 10 def table @table end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/exrt/cli/renderer.rb', line 10 def type @type end |
Instance Method Details
#header ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/exrt/cli/renderer.rb', line 26 def header if is_latest? latest_table_header elsif is_history? history_table_header else [] end end |
#history_table_header ⇒ Object
50 51 52 |
# File 'lib/exrt/cli/renderer.rb', line 50 def history_table_header %w[Currency Rate Date] end |
#is_history? ⇒ Boolean
22 23 24 |
# File 'lib/exrt/cli/renderer.rb', line 22 def is_history? type == Exrt::Cli::HISTORY end |
#is_latest? ⇒ Boolean
18 19 20 |
# File 'lib/exrt/cli/renderer.rb', line 18 def is_latest? type == Exrt::Cli::LATEST end |
#latest_table_header ⇒ Object
46 47 48 |
# File 'lib/exrt/cli/renderer.rb', line 46 def latest_table_header %w[Currency Rate] end |
#render ⇒ Object
54 55 56 |
# File 'lib/exrt/cli/renderer.rb', line 54 def render table.render(:ascii) end |