Class: HammerCLI::Output::Adapter::CSValues
- Inherits:
-
Abstract
- Object
- Abstract
- HammerCLI::Output::Adapter::CSValues
show all
- Defined in:
- lib/hammer_cli/output/adapter/csv.rb
Defined Under Namespace
Classes: Cell, FieldWrapper
Instance Method Summary
collapse
Methods inherited from Abstract
#initialize, #print_error
Instance Method Details
#print_collection(fields, collection) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/hammer_cli/output/adapter/csv.rb', line 154
def print_collection(fields, collection)
rows = row_data(fields, collection)
= rows.map{ |r| Cell.(r, @context) }.max_by{ || .size }
||= (fields)
csv_string = generate do |csv|
csv << if
rows.each do |row|
csv << Cell.values(, row)
end
end
puts csv_string
end
|
#print_message(msg, msg_params = {}) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/hammer_cli/output/adapter/csv.rb', line 169
def print_message(msg, msg_params={})
csv_string = generate do |csv|
id = msg_params["id"] || msg_params[:id]
name = msg_params["name"] || msg_params[:name]
labels = [_("Message")]
data = [msg.format(msg_params)]
if id
labels << _("Id")
data << id
end
if name
labels << _("Name")
data << name
end
csv << labels
csv << data
end
puts csv_string
end
|
#print_record(fields, record) ⇒ Object
150
151
152
|
# File 'lib/hammer_cli/output/adapter/csv.rb', line 150
def print_record(fields, record)
print_collection(fields, [record].flatten(1))
end
|
#row_data(fields, collection) ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/hammer_cli/output/adapter/csv.rb', line 142
def row_data(fields, collection)
result = []
collection.each do |data|
result << Cell.create_cells(FieldWrapper.wrap(fields), data, @formatters)
end
result
end
|
138
139
140
|
# File 'lib/hammer_cli/output/adapter/csv.rb', line 138
def tags
[:flat]
end
|