Class: Codabel::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/codabel/record.rb,
lib/codabel/record/header.rb,
lib/codabel/record/trailer.rb,
lib/codabel/record/movement.rb,
lib/codabel/record/movement21.rb,
lib/codabel/record/movement22.rb,
lib/codabel/record/movement23.rb,
lib/codabel/record/movement31.rb,
lib/codabel/record/movement32.rb,
lib/codabel/record/movement33.rb,
lib/codabel/record/new_balance.rb,
lib/codabel/record/old_balance.rb
more...

Defined Under Namespace

Classes: Header, Movement, Movement21, Movement22, Movement23, Movement31, Movement32, Movement33, NewBalance, OldBalance, Trailer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Record

Returns a new instance of Record.

[View source]

65
66
67
# File 'lib/codabel/record.rb', line 65

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.


68
69
70
# File 'lib/codabel/record.rb', line 68

def data
  @data
end

Class Method Details

.add_column(column) ⇒ Object

[View source]

45
46
47
# File 'lib/codabel/record.rb', line 45

def add_column(column)
  columns << column
end

.column(range, name, type, options = {}) ⇒ Object

Raises:

[View source]

36
37
38
39
40
41
42
43
# File 'lib/codabel/record.rb', line 36

def column(range, name, type, options = {})
  last_index = columns.last&.range&.max || 0
  raise Error, "Wrong column range #{range}, expected #{1+last_index}.." unless range.min == 1+last_index
  raise Error, "Wrong column range #{range}" if range.max > 128

  type = type.new if type.is_a?(Class)
  add_column Column.new(range, name, type, options)
end

.columnsObject

[View source]

50
51
52
# File 'lib/codabel/record.rb', line 50

def columns
  @columns ||= []
end

.for(data) ⇒ Object

[View source]

54
55
56
# File 'lib/codabel/record.rb', line 54

def for(data)
  new(data)
end

.header(data = {}) ⇒ Object

[View source]

4
5
6
# File 'lib/codabel/record.rb', line 4

def header(data = {})
  Header.new(data)
end

.movement(data = {}) ⇒ Object

[View source]

12
13
14
# File 'lib/codabel/record.rb', line 12

def movement(data = {})
  Movement.new(data)
end

.movement21(data = {}) ⇒ Object

[View source]

16
17
18
# File 'lib/codabel/record.rb', line 16

def movement21(data = {})
  Movement21.new(data)
end

.movement22(data = {}) ⇒ Object

[View source]

20
21
22
# File 'lib/codabel/record.rb', line 20

def movement22(data = {})
  Movement22.new(data)
end

.movement23(data = {}) ⇒ Object

[View source]

24
25
26
# File 'lib/codabel/record.rb', line 24

def movement23(data = {})
  Movement23.new(data)
end

.new_balance(data = {}) ⇒ Object

[View source]

28
29
30
# File 'lib/codabel/record.rb', line 28

def new_balance(data = {})
  NewBalance.new(data)
end

.old_balance(data = {}) ⇒ Object

[View source]

8
9
10
# File 'lib/codabel/record.rb', line 8

def old_balance(data = {})
  OldBalance.new(data)
end

.required?(data, ignore: []) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

58
59
60
61
62
# File 'lib/codabel/record.rb', line 58

def required?(data, ignore: [])
  columns
    .reject { |column| ignore.any? { |path| column.path_starts_with?(path) } }
    .any? { |column| column.specifics?(data) }
end

.trailer(data = {}) ⇒ Object

[View source]

32
33
34
# File 'lib/codabel/record.rb', line 32

def trailer(data = {})
  Trailer.new(data)
end

Instance Method Details

#actual_records(_file) ⇒ Object

[View source]

70
71
72
# File 'lib/codabel/record.rb', line 70

def actual_records(_file)
  [self]
end

#auto_enrich(_file) ⇒ Object

[View source]

74
75
76
# File 'lib/codabel/record.rb', line 74

def auto_enrich(_file)
  [self]
end

#to_codaObject

Raises:

[View source]

81
82
83
84
85
86
87
88
# File 'lib/codabel/record.rb', line 81

def to_coda
  str = self.class.columns.each_with_object('') do |column, memo|
    memo << column.to_coda(self)
  end
  return str if str.length == 128

  raise Error, "128 characters expected, got #{str.length}\n#{str}"
end

#validate!(file) ⇒ Object

[View source]

78
79
# File 'lib/codabel/record.rb', line 78

def validate!(file)
end