Module: CSVSjis

Defined in:
lib/csv_sjis.rb,
lib/csv_sjis/version.rb

Defined Under Namespace

Classes: Builder

Constant Summary collapse

SJIS_NAME =
'Shift_JIS'
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.open(file, mode = 'w', options = {}) {|builder| ... } ⇒ Object

Yields:

  • (builder)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/csv_sjis.rb', line 8

def open(file, mode = 'w', options = {})
  options = {
    encoding: SJIS_NAME,
    undef: :replace,
    invalid: :replace
  }.merge(options)

  file = File.open(file, mode, options)
  csv = CSV.new(file, encoding: options[:encoding])
  builder = Builder.new(csv, options[:encoding] == SJIS_NAME)

  yield(builder) if block_given?

  builder
end