Class: Ksef::FA3::TableColumn

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

Overview

Construction, invariants and serialisation for TableColumn.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Canonical

#with

Constructor Details

#initialize(name:, type:) ⇒ TableColumn

Returns a new instance of TableColumn.

Parameters:

  • name (String) —

    NKom, the column heading. TZnakowy2 permits an empty one, and a table whose first column labels the rows often has exactly that.

  • type (String) —

    Typ, required by the schema — there is no default, because a column's kind is a statement about its cells and guessing txt would make one.

Raises:



33
34
35
36
37
38
39
40
41
42
# File 'lib/ksef/fa3/table_column.rb', line 33

def initialize(name:, type:)
  canonical = Formatting.text(type)
  unless self.class.types.include?(canonical)
    raise ValidationError,
          "Column type #{type.inspect} is not one FA(3) permits. `Kol/@Typ` allows " \
          "#{self.class.types.join(", ")}."
  end

  super(name: Formatting.text(name).to_s, type: canonical)
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



13
14
15
# File 'lib/ksef/fa3/table_column.rb', line 13

def name
  @name
end

#type ⇒ Object (readonly)

Returns the value of attribute type

Returns:

  • (Object) —

    the current value of type



13
14
15
# File 'lib/ksef/fa3/table_column.rb', line 13

def type
  @type
end

Class Method Details

.types ⇒ Array<String>

Returns date, datetime, dec, int, time, txt.

Returns:

  • (Array<String>) —

    date, datetime, dec, int, time, txt



21
22
23
24
25
26
# File 'lib/ksef/fa3/table_column.rb', line 21

def self.types
  Generated::Types::ALL
    .fetch("Faktura/Zalacznik/BlokDanych/Tabela/TNaglowek/Kol")[:attributes]
    .find { |attribute| attribute[:name] == "Typ" }
    .fetch(:values)
end

Instance Method Details

#to_fa3 ⇒ Object



44
45
46
# File 'lib/ksef/fa3/table_column.rb', line 44

def to_fa3
  Serializer::Element.new(text: nil, attributes: { "Typ" => type }, children: { "NKom" => name })
end