Class: HammerCLI::Output::Adapter::CSValues::Cell
- Inherits:
-
Object
- Object
- HammerCLI::Output::Adapter::CSValues::Cell
- Defined in:
- lib/hammer_cli/output/adapter/csv.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#field_wrapper ⇒ Object
Returns the value of attribute field_wrapper.
Class Method Summary collapse
- .create_cells(field_wrappers, data, formatters) ⇒ Object
- .headers(cells, context) ⇒ Object
- .values(headers, cells) ⇒ Object
Instance Method Summary collapse
- #formatted_value ⇒ Object
- #in_column?(header) ⇒ Boolean
-
#initialize(field_wrapper, data, formatters) ⇒ Cell
constructor
A new instance of Cell.
Constructor Details
#initialize(field_wrapper, data, formatters) ⇒ Cell
Returns a new instance of Cell.
11 12 13 14 15 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 11 def initialize(field_wrapper, data, formatters) @field_wrapper = field_wrapper @data = data @formatters = formatters end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 9 def data @data end |
#field_wrapper ⇒ Object
Returns the value of attribute field_wrapper.
9 10 11 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 9 def field_wrapper @field_wrapper end |
Class Method Details
.create_cells(field_wrappers, data, formatters) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 17 def self.create_cells(field_wrappers, data, formatters) results = [] field_wrappers.each do |field_wrapper| field = field_wrapper.field if field.is_a? Fields::Collection results = results + (field, data, formatters) elsif field.is_a?(Fields::ContainerField) results = results + (field, data, formatters) else results << Cell.new(field_wrapper, data, formatters) end end return results end |
.headers(cells, context) ⇒ Object
45 46 47 48 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 45 def self.headers(cells, context) cells.map(&:field_wrapper).select { |fw| ! fw.is_id? || context[:show_ids] }.map(&:display_name) end |
.values(headers, cells) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 38 def self.values(headers, cells) headers.map do |header| cell = cells.find { |cell| cell.in_column?(header) } cell ? cell.formatted_value : '' end end |
Instance Method Details
#formatted_value ⇒ Object
32 33 34 35 36 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 32 def formatted_value WrapperFormatter.new( @formatters.formatter_for_type(@field_wrapper.field.class), @field_wrapper.field.parameters).format(value) end |
#in_column?(header) ⇒ Boolean
50 51 52 |
# File 'lib/hammer_cli/output/adapter/csv.rb', line 50 def in_column?(header) self.field_wrapper.display_name == header end |