Class: Mindee::V1::Parsing::Standard::TaxField
- Inherits:
-
BaseField
- Object
- AbstractField
- BaseField
- Mindee::V1::Parsing::Standard::TaxField
- Defined in:
- lib/mindee/v1/parsing/standard/tax_field.rb
Overview
Represents tax information.
Instance Attribute Summary collapse
-
#base ⇒ Float
readonly
Tax base.
-
#code ⇒ String
readonly
Tax code.
-
#rate ⇒ Float
readonly
Tax rate percentage.
-
#value ⇒ Float?
readonly
Tax value as 3 decimal float.
Attributes inherited from BaseField
Attributes inherited from AbstractField
#bounding_box, #confidence, #page_id, #polygon
Instance Method Summary collapse
-
#initialize(prediction, page_id) ⇒ TaxField
constructor
A new instance of TaxField.
- #print_float(value) ⇒ Object
- #printable_values ⇒ Hash
- #to_s ⇒ String
- #to_table_line ⇒ String
Methods inherited from AbstractField
array_confidence, array_sum, float_to_string
Constructor Details
#initialize(prediction, page_id) ⇒ TaxField
Returns a new instance of TaxField.
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
#base ⇒ Float (readonly)
Tax base
22 23 24 |
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 22 def base @base end |
#code ⇒ String (readonly)
Tax code
19 20 21 |
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 19 def code @code end |
#rate ⇒ Float (readonly)
Tax rate percentage
16 17 18 |
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 16 def rate @rate end |
#value ⇒ Float? (readonly)
Tax value as 3 decimal float
13 14 15 |
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 13 def value @value end |
Instance Method Details
#print_float(value) ⇒ Object
35 36 37 |
# File 'lib/mindee/v1/parsing/standard/tax_field.rb', line 35 def print_float(value) format('%.2f', value) end |
#printable_values ⇒ 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_s ⇒ 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_line ⇒ 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 |