Class: Mindee::Input::DataSchemaField

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/input/data_schema.rb

Overview

Data Schema Field.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ DataSchemaField

Returns a new instance of DataSchemaField.

Parameters:

  • field (Hash)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mindee/input/data_schema.rb', line 28

def initialize(field)
  field.transform_keys!(&:to_sym)
  @name = field[:name]
  @title = field[:title]
  @is_array = field[:is_array]
  @type = field[:type]
  @classification_values = field[:classification_values]
  @unique_values = field[:unique_values]
  @description = field[:description]
  @guidelines = field[:guidelines]
  @nested_fields = field[:nested_fields]
end

Instance Attribute Details

#classification_valuesArray<String>? (readonly)

Returns Allowed values when type is classification. Leave empty for other types.

Returns:

  • (Array<String>, nil)

    Allowed values when type is classification. Leave empty for other types.



16
17
18
# File 'lib/mindee/input/data_schema.rb', line 16

def classification_values
  @classification_values
end

#descriptionString? (readonly)

Returns Detailed description of what this field represents.

Returns:

  • (String, nil)

    Detailed description of what this field represents.



21
22
23
# File 'lib/mindee/input/data_schema.rb', line 21

def description
  @description
end

#guidelinesString? (readonly)

Returns Optional extraction guidelines.

Returns:

  • (String, nil)

    Optional extraction guidelines.



23
24
25
# File 'lib/mindee/input/data_schema.rb', line 23

def guidelines
  @guidelines
end

#is_arrayBoolean (readonly)

Returns Whether this field can contain multiple values.

Returns:

  • (Boolean)

    Whether this field can contain multiple values.



12
13
14
# File 'lib/mindee/input/data_schema.rb', line 12

def is_array
  @is_array
end

#nameString (readonly)

Returns Name of the field in the data schema.

Returns:

  • (String)

    Name of the field in the data schema.



10
11
12
# File 'lib/mindee/input/data_schema.rb', line 10

def name
  @name
end

#nested_fieldsArray<Hash>? (readonly)

Returns Nested fields.

Returns:

  • (Array<Hash>, nil)

    Nested fields.



25
26
27
# File 'lib/mindee/input/data_schema.rb', line 25

def nested_fields
  @nested_fields
end

#titleString (readonly)

Returns Display name for the field, also impacts inference results.

Returns:

  • (String)

    Display name for the field, also impacts inference results.



8
9
10
# File 'lib/mindee/input/data_schema.rb', line 8

def title
  @title
end

#typeString (readonly)

Returns Data type of the field.

Returns:

  • (String)

    Data type of the field.



14
15
16
# File 'lib/mindee/input/data_schema.rb', line 14

def type
  @type
end

#unique_valuesBoolean? (readonly)

Only applicable if is_array is True.

Returns:

  • (Boolean, nil)

    Whether to remove duplicate values in the array.



19
20
21
# File 'lib/mindee/input/data_schema.rb', line 19

def unique_values
  @unique_values
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mindee/input/data_schema.rb', line 42

def to_hash
  out = {
    name: @name,
    title: @title,
    is_array: @is_array,
    type: @type,
  } # @type var out: Hash[Symbol, untyped]
  out[:classification_values] = @classification_values unless @classification_values.nil?
  out[:unique_values] = @unique_values unless @unique_values.nil?
  out[:description] = @description unless @description.nil?
  out[:guidelines] = @guidelines unless @guidelines.nil?
  out[:nested_fields] = @nested_fields unless @nested_fields.nil?
  out
end

#to_sString

Returns:

  • (String)


58
59
60
# File 'lib/mindee/input/data_schema.rb', line 58

def to_s
  to_hash.to_json
end