Class: Philiprehberger::CsvKit::Dialect
- Inherits:
-
Object
- Object
- Philiprehberger::CsvKit::Dialect
- Defined in:
- lib/philiprehberger/csv_kit/dialect.rb
Overview
Predefined and custom CSV dialects for controlling parsing and writing behavior.
Constant Summary collapse
- PRESETS =
{ excel: { col_sep: ',', row_sep: "\r\n", strip: true }, excel_tab: { col_sep: "\t" }, unix: { col_sep: ',', row_sep: "\n" } }.freeze
- OPTION_MAP =
{ delimiter: :col_sep, quote: :quote_char, line_ending: :row_sep }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(name_or_hash) ⇒ Dialect
constructor
Build a Dialect from a preset name or a custom options hash.
-
#merge_into(base) ⇒ Hash
Merge dialect options into a base CSV options hash.
Constructor Details
#initialize(name_or_hash) ⇒ Dialect
Build a Dialect from a preset name or a custom options hash.
25 26 27 |
# File 'lib/philiprehberger/csv_kit/dialect.rb', line 25 def initialize(name_or_hash) @options = resolve(name_or_hash) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/philiprehberger/csv_kit/dialect.rb', line 19 def @options end |
Instance Method Details
#merge_into(base) ⇒ Hash
Merge dialect options into a base CSV options hash.
33 34 35 |
# File 'lib/philiprehberger/csv_kit/dialect.rb', line 33 def merge_into(base) base.merge(@options) end |