Class: Csb::Builder
- Inherits:
-
Object
- Object
- Csb::Builder
- Defined in:
- lib/csb/builder.rb
Constant Summary collapse
- UTF8_BOM =
"\xEF\xBB\xBF".freeze
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#items ⇒ Object
Returns the value of attribute items.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#utf8_bom ⇒ Object
readonly
Returns the value of attribute utf8_bom.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(output = '', items: [], utf8_bom: false) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
8 9 10 |
# File 'lib/csb/builder.rb', line 8 def cols @cols end |
#items ⇒ Object
Returns the value of attribute items.
8 9 10 |
# File 'lib/csb/builder.rb', line 8 def items @items end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/csb/builder.rb', line 8 def output @output end |
#utf8_bom ⇒ Object (readonly)
Returns the value of attribute utf8_bom.
8 9 10 |
# File 'lib/csb/builder.rb', line 8 def utf8_bom @utf8_bom end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/csb/builder.rb', line 18 def build output << UTF8_BOM if utf8_bom output << CSV.generate_line(cols.headers) items.each do |item| output << CSV.generate_line(cols.values_by_item(item)) rescue => error break if Csb.configuration.ignore_class_names.include?(error.class.name) raise error end output end |