Class: Ksef::FA3::Attachment

Inherits:
Data
  • Object
show all
Includes:
Canonical
Defined in:
lib/ksef/fa3/attachment.rb,
lib/ksef/fa3/attachment.rb

Overview

Construction, invariants and serialisation for Attachment.

Constant Summary collapse

NEEDS_BLOCK =
"An attachment needs at least one data block. `BlokDanych` is minOccurs=1 " \
"within `Zalacznik`, so an attachment without one cannot be serialised."

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Canonical

#with

Constructor Details

#initialize(blocks:) ⇒ Attachment

Returns a new instance of Attachment.

Parameters:

Raises:



29
30
31
32
33
34
# File 'lib/ksef/fa3/attachment.rb', line 29

def initialize(blocks:)
  entries = Correction.wrap(blocks)
  raise ValidationError, NEEDS_BLOCK if entries.empty?

  super(blocks: entries.dup.freeze)
end

Instance Attribute Details

#blocks ⇒ Object (readonly)

Returns the value of attribute blocks

Returns:

  • (Object) —

    the current value of blocks



17
18
19
# File 'lib/ksef/fa3/attachment.rb', line 17

def blocks
  @blocks
end

Class Method Details

.wrap(value) ⇒ Object

An Ksef::FA3::Attachment, or the blocks to make one from. The one-block case is the common one and does not deserve two levels of ceremony; Builder#attachment is the caller.



38
# File 'lib/ksef/fa3/attachment.rb', line 38

def self.wrap(value) = value.is_a?(Attachment) ? value : new(blocks: value)

Instance Method Details

#to_fa3 ⇒ Object



40
# File 'lib/ksef/fa3/attachment.rb', line 40

def to_fa3 = { "BlokDanych" => blocks.map(&:to_fa3) }