Class: Mindee::V1::Parsing::Standard::TaxField

Inherits:
BaseField show all
Defined in:
lib/mindee/v1/parsing/standard/tax_field.rb

Overview

Represents tax information.

Instance Attribute Summary collapse

Attributes inherited from BaseField

#reconstructed

Attributes inherited from AbstractField

#bounding_box, #confidence, #page_id, #polygon

Instance Method Summary collapse

Methods inherited from AbstractField

array_confidence, array_sum, float_to_string

Constructor Details

#initialize(prediction, page_id) ⇒ TaxField

Returns a new instance of TaxField.

Parameters:

  • prediction (Hash)
  • page_id (Integer, nil)


26
27
28
29
30
31
32
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 26

def initialize(prediction, page_id)
  super
  @value = prediction['value']&.round(3)
  @rate = prediction['rate'].to_f unless prediction['rate'].nil?
  @base = prediction['base'].to_f unless prediction['base'].nil?
  @code = prediction['code'] unless prediction['code'] == 'None'
end

Instance Attribute Details

#baseFloat (readonly)

Tax base

Returns:

  • (Float)


22
23
24
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 22

def base
  @base
end

#codeString (readonly)

Tax code

Returns:

  • (String)


19
20
21
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 19

def code
  @code
end

#rateFloat (readonly)

Tax rate percentage

Returns:

  • (Float)


16
17
18
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 16

def rate
  @rate
end

#valueFloat? (readonly)

Tax value as 3 decimal float

Returns:

  • (Float, nil)


13
14
15
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 13

def value
  @value
end

Instance Method Details

Parameters:

  • value (Float)


35
36
37
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 35

def print_float(value)
  format('%.2f', value)
end

#printable_valuesHash

Returns:

  • (Hash)


51
52
53
54
55
56
57
58
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 51

def printable_values
  out_h = {} # @type var out_h: Hash[Symbol, String]
  out_h[:code] = @code.nil? ? '' : @code
  out_h[:base] = @base.nil? ? '' : print_float(@base)
  out_h[:rate] = @rate.nil? ? '' : print_float(@rate).to_s
  out_h[:value] = @value.to_s.empty? ? '' : print_float(@value.to_f).to_s
  out_h
end

#to_sString

Returns:

  • (String)


40
41
42
43
44
45
46
47
48
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 40

def to_s
  printable = printable_values
  out_str = String.new
  out_str << "Base: #{printable[:base]}"
  out_str << ", Code: #{printable[:code]}"
  out_str << ", Rate (%): #{printable[:rate]}"
  out_str << ", Amount: #{printable[:value]}"
  out_str.strip
end

#to_table_lineString

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 61

def to_table_line
  printable = printable_values
  out_str = String.new
  out_str << "| #{printable[:base].ljust(13, ' ')}"
  out_str << " | #{printable[:code].ljust(6, ' ')}"
  out_str << " | #{printable[:rate].ljust(8, ' ')}"
  out_str << " | #{printable[:value].ljust(13, ' ')} |"
  out_str.strip
end