Class: Norma43::Models::Document

Inherits:
Object
  • Object
show all
Includes:
Mixins::AttributesAssignment
Defined in:
lib/norma43/models/document.rb

Constant Summary

Constants included from Mixins::AttributesAssignment

Mixins::AttributesAssignment::EMPTY_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::AttributesAssignment

#attributes, #attributes=

Constructor Details

#initialize(attributes = EMPTY_ATTRIBUTES) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/norma43/models/document.rb', line 10

def initialize(attributes = EMPTY_ATTRIBUTES)
  @id,
  @created_at,
  @delivery_number,
  @file_type,
  @name,
  @number_of_lines,
  accounts = Hash(attributes).values_at(
    :id,
    :created_at,
    :delivery_number,
    :file_type,
    :name,
    :number_of_lines,
    :accounts)
  @accounts = Array(accounts).map { || Account.new() }
end

Instance Attribute Details

#accountsObject

Returns the value of attribute accounts.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def accounts
  @accounts
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def created_at
  @created_at
end

#delivery_numberObject

Returns the value of attribute delivery_number.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def delivery_number
  @delivery_number
end

#file_typeObject

Returns the value of attribute file_type.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def file_type
  @file_type
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def name
  @name
end

#number_of_linesObject

Returns the value of attribute number_of_lines.



8
9
10
# File 'lib/norma43/models/document.rb', line 8

def number_of_lines
  @number_of_lines
end

Instance Method Details

#transaction_dateObject

Deprecated.

Please ask each transaction inside accounts for their transaction_date instead



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/norma43/models/document.rb', line 29

def transaction_date
  warn "[DEPRECATION] `transaction_date` is deprecated, use `#transaction_date` from transactions in `#accounts` instead"
  date = nil

  accounts.flat_map(&:transactions).each { |transaction|
    date = transaction&.transaction_date
    break unless date.nil?
  }

  date
end