Class: Bismas::Writer

Inherits:
Base
  • Object
show all
Defined in:
lib/bismas/writer.rb

Constant Summary collapse

DEFAULT_IO =
$stdout

Instance Attribute Summary

Attributes inherited from Base

#auto_id, #io, #key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#reset

Constructor Details

#initialize(options = {}) ⇒ Writer

Returns a new instance of Writer.



51
52
53
54
55
56
57
58
59
# File 'lib/bismas/writer.rb', line 51

def initialize(options = {})
  @category_length = options[:category_length] || DEFAULT_CATEGORY_LENGTH
  @padding_length  = options[:padding_length]  || DEFAULT_PADDING_LENGTH
  @sort            = options[:sort]

  @chars = Bismas.chars(options)

  super
end

Class Method Details

.open(*args, &block) ⇒ Object



45
46
47
# File 'lib/bismas/writer.rb', line 45

def open(*args, &block)
  file_method(nil, 'wb', *args, &block)
end

.write(*args, &block) ⇒ Object



37
38
39
# File 'lib/bismas/writer.rb', line 37

def write(*args, &block)
  new(args.extract_options!, &block).write(*args)
end

.write_file(*args, &block) ⇒ Object



41
42
43
# File 'lib/bismas/writer.rb', line 41

def write_file(*args, &block)
  file_method(:write, 'wb', *args, &block)
end

Instance Method Details

#[]=(id, record) ⇒ Object



79
80
81
# File 'lib/bismas/writer.rb', line 79

def []=(id, record)
  write_i(id, record)
end

#put(record, *args) ⇒ Object Also known as: <<



69
70
71
72
73
74
75
# File 'lib/bismas/writer.rb', line 69

def put(record, *args)
  record.is_a?(Hash) ?
    write_i(nil, record, *args) :
    write_i(*args.unshift(*record))

  self
end

#write(records, *args) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/bismas/writer.rb', line 61

def write(records, *args)
  !records.is_a?(Hash) ?
    records.each { |record| write_i(nil, record, *args) } :
    records.each { |id, record| write_i(id, record, *args) }

  self
end