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

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

Overview

Represents tax information.

Instance Attribute Summary collapse

Attributes inherited from Field

#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)


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

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)


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

def base
  @base
end

#codeString (readonly)

Tax code

Returns:

  • (String)


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

def code
  @code
end

#rateFloat (readonly)

Tax rate percentage

Returns:

  • (Float)


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

def rate
  @rate
end

#valueFloat? (readonly)

Tax value as 3 decimal float

Returns:

  • (Float, nil)


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

def value
  @value
end

Instance Method Details

Parameters:

  • value (Float)


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

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

#printable_valuesHash

Returns:

  • (Hash)


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

def printable_values
  out_h = {}
  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.nil? ? '' : print_float(@value).to_s
  out_h
end

#to_sString

Returns:

  • (String)


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

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)


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

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