Class: Mindee::Parsing::Standard::LocaleField

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/standard/locale_field.rb

Overview

Represents locale information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, _page_id = nil) ⇒ LocaleField

Returns a new instance of LocaleField.

Parameters:

  • prediction (Hash)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mindee/parsing/standard/locale_field.rb', line 25

def initialize(prediction, _page_id = nil)
  value_key = if !prediction.include?('value') || prediction['value'].nil?
                'language'
              else
                'value'
              end
  @confidence = prediction['confidence']
  @value = prediction[value_key]
  @language = prediction['language']
  @country = prediction['country']
  @currency = prediction['currency']
end

Instance Attribute Details

#confidenceFloat (readonly)

The confidence score, value will be between 0.0 and 1.0

Returns:

  • (Float)


10
11
12
# File 'lib/mindee/parsing/standard/locale_field.rb', line 10

def confidence
  @confidence
end

#countryString? (readonly)

Country code in ISO 3166-1 alpha-2 format.

Returns:

  • (String, nil)


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

def country
  @country
end

#currencyString (readonly)

Currency code in ISO 4217 format.

Returns:

  • (String)


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

def currency
  @currency
end

#languageString (readonly)

Language code in ISO 639-1 format.

Returns:

  • (String)


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

def language
  @language
end

#valueString (readonly)

Language code, with country code when available.

Returns:

  • (String)


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

def value
  @value
end

Instance Method Details

#to_sString

Returns:

  • (String)


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

def to_s
  out_str = String.new
  out_str << "#{@value}; " unless @value.nil?
  out_str << "#{@language}; " if @language
  out_str << "#{@country}; " if @country
  out_str << "#{@currency}; " if @currency
  out_str.strip
end