Class: Mindee::Parsing::Standard::TaxField
- Inherits:
-
Field
- Object
- AbstractField
- Field
- Mindee::Parsing::Standard::TaxField
- Defined in:
- lib/mindee/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 Field
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.
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
#base ⇒ Float (readonly)
Tax base
21 22 23 |
# File 'lib/mindee/parsing/standard/tax_field.rb', line 21 def base @base end |
#code ⇒ String (readonly)
Tax code
18 19 20 |
# File 'lib/mindee/parsing/standard/tax_field.rb', line 18 def code @code end |
#rate ⇒ Float (readonly)
Tax rate percentage
15 16 17 |
# File 'lib/mindee/parsing/standard/tax_field.rb', line 15 def rate @rate end |
#value ⇒ Float? (readonly)
Tax value as 3 decimal float
12 13 14 |
# File 'lib/mindee/parsing/standard/tax_field.rb', line 12 def value @value end |
Instance Method Details
#print_float(value) ⇒ Object
34 35 36 |
# File 'lib/mindee/parsing/standard/tax_field.rb', line 34 def print_float(value) format('%.2f', value) end |
#printable_values ⇒ 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_s ⇒ 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_line ⇒ 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 |