Class: Ksef::FA3::MetaEntry

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

Overview

Construction, invariants and serialisation for MetaEntry.

Constant Summary collapse

NEEDS_BOTH =
"An attachment's metadata entry needs a key and a value. `ZKlucz` and " \
"`ZWartosc` are both mandatory within `MetaDane`."

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Canonical

#with

Constructor Details

#initialize(key:, value:) ⇒ MetaEntry

Returns a new instance of MetaEntry.

Parameters:

  • key (String) —

    ZKlucz / TKlucz, TZnakowy (256)

  • value (String) —

    ZWartosc / TWartosc, TZnakowy (256)

Raises:



31
32
33
34
35
36
# File 'lib/ksef/fa3/meta_entry.rb', line 31

def initialize(key:, value:)
  canonical = { key: Formatting.text(key), value: Formatting.text(value) }
  raise ValidationError, NEEDS_BOTH if canonical.values.any? { |v| v.nil? || v.empty? }

  super(**canonical)
end

Instance Attribute Details

#key ⇒ Object (readonly)

Returns the value of attribute key

Returns:

  • (Object) —

    the current value of key



18
19
20
# File 'lib/ksef/fa3/meta_entry.rb', line 18

def key
  @key
end

#value ⇒ Object (readonly)

Returns the value of attribute value

Returns:

  • (Object) —

    the current value of value



18
19
20
# File 'lib/ksef/fa3/meta_entry.rb', line 18

def value
  @value
end

Instance Method Details

#to_fa3(key_element:, value_element:) ⇒ Object

Parameters:

  • key_element (String) —

    "ZKlucz" or "TKlucz"

  • value_element (String) —

    "ZWartosc" or "TWartosc"



40
41
42
# File 'lib/ksef/fa3/meta_entry.rb', line 40

def to_fa3(key_element:, value_element:)
  { key_element => key, value_element => value }
end