Class: AmazonTRP::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon-textract-parser-ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeForm

Returns a new instance of Form.



262
263
264
265
# File 'lib/amazon-textract-parser-ruby.rb', line 262

def initialize
  @fields = []
  @fieldsMap = {}
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



260
261
262
# File 'lib/amazon-textract-parser-ruby.rb', line 260

def fields
  @fields
end

Instance Method Details

#addField(field) ⇒ Object



267
268
269
270
# File 'lib/amazon-textract-parser-ruby.rb', line 267

def addField(field)
  @fields.append(field)
  @fieldsMap[field.key.text] = field
end

#findFieldByKey(key) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/amazon-textract-parser-ruby.rb', line 295

def findFieldByKey(key)
  fields = findFieldsByKey(key)
  # Choose the shortest match
  match = nil
  matchLength = 0
  fields.each do |f|
    if match.nil? || f.key.text.length < matchLength
      match = f
      matchLength = f.key.text.length
    end
  end
  return match
end

#findFieldsByKey(key) ⇒ Object



284
285
286
287
288
289
290
291
292
293
# File 'lib/amazon-textract-parser-ruby.rb', line 284

def findFieldsByKey(key)
  searchKey = key.downcase()
  results = []
  @fields.each do |field|
    if field.key && (field.key.text.downcase.include?(searchKey))
      results.append(field)
    end
  end
  return results
end

#getFieldByKey(key) ⇒ Object



280
281
282
# File 'lib/amazon-textract-parser-ruby.rb', line 280

def getFieldByKey(key)
  @fieldsMap[key]
end

#to_sObject



272
273
274
275
276
277
278
# File 'lib/amazon-textract-parser-ruby.rb', line 272

def to_s
  s = "Form fields:\n"
  @fields.each do |field|
    s = s + field.to_s + "\n"
  end
  return s
end