Class: HoneyFormat::Row
- Inherits:
-
Struct
- Object
- Struct
- HoneyFormat::Row
- Defined in:
- lib/honey_format/matrix/row.rb
Overview
Default row builder
Class Method Summary collapse
-
.call(row) ⇒ Row
Create a row.
Instance Method Summary collapse
-
#inspect ⇒ String
(also: #to_s)
Describe the contents of this row in a string.
-
#to_csv(columns: nil) ⇒ String
Represent row as CSV.
Class Method Details
.call(row) ⇒ Row
Create a row
12 13 14 |
# File 'lib/honey_format/matrix/row.rb', line 12 def self.call(row) new(*row) end |
Instance Method Details
#inspect ⇒ String Also known as: to_s
Describe the contents of this row in a string.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/honey_format/matrix/row.rb', line 31 def inspect attributes = members.map do |field| value = self[field] value = "\"#{value}\"" if value.is_a?(String) [field, value].join('=') end.join(', ') "#<Row #{attributes}>" end |
#to_csv(columns: nil) ⇒ String
Represent row as CSV
20 21 22 23 24 25 26 27 |
# File 'lib/honey_format/matrix/row.rb', line 20 def to_csv(columns: nil) attributes = members attributes = columns & attributes if columns row = attributes.map! { |column| to_csv_value(column) } ::CSV.generate_line(row) end |