require 'ocr_space/file_post' module OcrSpace class FromFile attr_reader :data def initialize(apikey: ENV['ocr_api_key'], language: 'eng', isOverlayRequired: false, files: nil) @file = File.new(files) @data = OcrSpace::FilePost.post('/parse/image', body: { apikey: apikey, language: language, isOverlayRequired: isOverlayRequired, files: @file }) @data = @data.parsed_response['ParsedResults'] end def text_data data[0]['ParsedText'].delete("\n").delete("\r").strip end end end