Class: Mindee::Product::FR::EnergyBill::EnergyBillV1EnergyUsage

Inherits:
Mindee::Parsing::Standard::FeatureField show all
Includes:
Mindee::Parsing::Standard
Defined in:
lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb

Overview

Details of energy consumption.

Instance Attribute Summary collapse

Attributes inherited from Mindee::Parsing::Standard::AbstractField

#bounding_box, #confidence, #page_id, #polygon

Instance Method Summary collapse

Methods inherited from Mindee::Parsing::Standard::FeatureField

#format_for_display

Methods inherited from Mindee::Parsing::Standard::AbstractField

array_confidence, array_sum, float_to_string

Constructor Details

#initialize(prediction, page_id) ⇒ EnergyBillV1EnergyUsage

Returns a new instance of EnergyBillV1EnergyUsage.

Parameters:

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


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 39

def initialize(prediction, page_id)
  super
  @consumption = prediction['consumption']
  @description = prediction['description']
  @end_date = prediction['end_date']
  @start_date = prediction['start_date']
  @tax_rate = prediction['tax_rate']
  @total = prediction['total']
  @unit = prediction['unit']
  @unit_price = prediction['unit_price']
  @page_id = page_id
end

Instance Attribute Details

#consumptionFloat (readonly)

The price per unit of energy consumed.

Returns:

  • (Float)


14
15
16
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 14

def consumption
  @consumption
end

#descriptionString (readonly)

Description or details of the energy usage.

Returns:

  • (String)


17
18
19
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 17

def description
  @description
end

#end_dateString (readonly)

The end date of the energy usage.

Returns:

  • (String)


20
21
22
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 20

def end_date
  @end_date
end

#start_dateString (readonly)

The start date of the energy usage.

Returns:

  • (String)


23
24
25
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 23

def start_date
  @start_date
end

#tax_rateFloat (readonly)

The rate of tax applied to the total cost.

Returns:

  • (Float)


26
27
28
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 26

def tax_rate
  @tax_rate
end

#totalFloat (readonly)

The total cost of energy consumed.

Returns:

  • (Float)


29
30
31
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 29

def total
  @total
end

#unitString (readonly)

The unit of measurement for energy consumption.

Returns:

  • (String)


32
33
34
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 32

def unit
  @unit
end

#unit_priceFloat (readonly)

The price per unit of energy consumed.

Returns:

  • (Float)


35
36
37
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 35

def unit_price
  @unit_price
end

Instance Method Details

#printable_valuesHash

Returns:

  • (Hash)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 53

def printable_values
  printable = {}
  printable[:consumption] =
    @consumption.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@consumption)
  printable[:description] = format_for_display(@description)
  printable[:end_date] = format_for_display(@end_date)
  printable[:start_date] = format_for_display(@start_date)
  printable[:tax_rate] =
    @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate)
  printable[:total] =
    @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total)
  printable[:unit] = format_for_display(@unit)
  printable[:unit_price] =
    @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price)
  printable
end

#table_printable_valuesHash

Returns:

  • (Hash)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 71

def table_printable_values
  printable = {}
  printable[:consumption] =
    @consumption.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@consumption)
  printable[:description] = format_for_display(@description, 36)
  printable[:end_date] = format_for_display(@end_date, 10)
  printable[:start_date] = format_for_display(@start_date, nil)
  printable[:tax_rate] =
    @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate)
  printable[:total] =
    @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total)
  printable[:unit] = format_for_display(@unit, nil)
  printable[:unit_price] =
    @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price)
  printable
end

#to_sString

Returns:

  • (String)


104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 104

def to_s
  printable = printable_values
  out_str = String.new
  out_str << "\n  :Consumption: #{printable[:consumption]}"
  out_str << "\n  :Description: #{printable[:description]}"
  out_str << "\n  :End Date: #{printable[:end_date]}"
  out_str << "\n  :Start Date: #{printable[:start_date]}"
  out_str << "\n  :Tax Rate: #{printable[:tax_rate]}"
  out_str << "\n  :Total: #{printable[:total]}"
  out_str << "\n  :Unit of Measure: #{printable[:unit]}"
  out_str << "\n  :Unit Price: #{printable[:unit_price]}"
  out_str
end

#to_table_lineString

Returns:

  • (String)


89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb', line 89

def to_table_line
  printable = table_printable_values
  out_str = String.new
  out_str << format('| %- 12s', printable[:consumption])
  out_str << format('| %- 37s', printable[:description])
  out_str << format('| %- 11s', printable[:end_date])
  out_str << format('| %- 11s', printable[:start_date])
  out_str << format('| %- 9s', printable[:tax_rate])
  out_str << format('| %- 10s', printable[:total])
  out_str << format('| %- 16s', printable[:unit])
  out_str << format('| %- 11s', printable[:unit_price])
  out_str << '|'
end