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.
-
#csv_options ⇒ Object
readonly
Returns the value of attribute csv_options.
-
#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: [], **kwargs) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(output = +'',, items: [], **kwargs) ⇒ Builder
Returns a new instance of Builder.
11 12 13 14 15 16 17 |
# File 'lib/csb/builder.rb', line 11 def initialize(output = +'', items: [], **kwargs) @output = output @cols = Cols.new @items = items @utf8_bom = kwargs.fetch(:utf8_bom) { Csb.configuration.utf8_bom } @csv_options = kwargs.fetch(:csv_options) { Csb.configuration. } end |
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 |
#csv_options ⇒ Object (readonly)
Returns the value of attribute csv_options.
8 9 10 |
# File 'lib/csb/builder.rb', line 8 def @csv_options 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
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/csb/builder.rb', line 19 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 |