class AmazonTRP::Form

Attributes

fields[R]

Public Class Methods

new() click to toggle source
# File lib/amazon-textract-parser-ruby.rb, line 262
def initialize
  @fields = []
  @fieldsMap = {}
end

Public Instance Methods

addField(field) click to toggle source
# File lib/amazon-textract-parser-ruby.rb, line 267
def addField(field)
  @fields.append(field)
  @fieldsMap[field.key.text] = field
end
findFieldByKey(key) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/amazon-textract-parser-ruby.rb, line 280
def getFieldByKey(key)
  @fieldsMap[key]
end
to_s() click to toggle source
# 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