ocr_space 1.0 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d6af41320b1f019a718b0a4bdf82635ff45fb83
4
- data.tar.gz: fde10be5e3f5c2305ef6ee40bcfa55e562180349
3
+ metadata.gz: 482aa09d94f5f2a4eb0bffba5b4a3a4e3eebb2ba
4
+ data.tar.gz: 343592d8b308393c5fd62b516b754cd4af7cabb9
5
5
  SHA512:
6
- metadata.gz: 43e8bbbc932dc61a035e38948151ef853d07b87910a706fe81559ebb7eacd757875cc54bbd03da9fae6e93bc034f2bfc6401006d31063dfd8d36bd1f25cd92c5
7
- data.tar.gz: 68adbde17acbb1fa00fd87050a51c85db4fb8c6e6bdeb913694d9da9f45033301fb61bf249e77f38e4e650ffc3b827377ea5ae8b3ab9825482e0f5331bbe2c98
6
+ metadata.gz: 7b08e263106cd8c8b04e6bba34eccaf5e1727892794a954f168a3d28f4dad951469175a58fb59cb1de1e390392702e76af92365e6454f6bb104034d3c0e54c6f
7
+ data.tar.gz: a14245907adc60dc9493b7018ee72578e413180f5600dddd573f4a141083f27994520c8da287084f540ea2a4764b84534e21d146cda0cf7006dd798cf2792293
data/README.md CHANGED
@@ -28,12 +28,26 @@ Hosted at [rubygems.org](https://rubygems.org/gems/ocr_space)
28
28
 
29
29
  ![Nicola Tesla](http://bit.ly/2ih9aXt)
30
30
 
31
- #To convert images from url
31
+ ## Instantiate OcrSpace resource with apikey
32
32
 
33
33
  ```ruby
34
34
  require 'ocr_space'
35
35
 
36
- result = OcrSpace::FromUrl.new(apikey: "YOUR API KEY", url: "http://bit.ly/2ih9aXt")
36
+ resource = OcrSpace::Resource.new(apikey: "YOUR API KEY")
37
+ #By default it picks up ocr_api_key='YOUR API KEY' from your env variables
38
+ ```
39
+ #ENV Variables (Optional)
40
+ setting env variables with api key is optional but for commandline interface to work you will have to set ENV variable 'ocr_api_key' to your apikey. For more details on Command line interface, scroll to the bottom of this page.
41
+
42
+ ```
43
+ $ export ocr_api_key='YOUR API KEY'
44
+ ```
45
+
46
+ #To convert images from url
47
+
48
+ ```ruby
49
+
50
+ result = resource.convert url: "http://bit.ly/2ih9aXt"
37
51
 
38
52
  puts result.data
39
53
  => #[{"TextOverlay"=>{"Lines"=>[], "HasOverlay"=>false, "Message"=>"Text overlay is not provided as it is not requested"}, "FileParseExitCode"=>1, "ParsedText"=>"If you want to find the secrets of the \r\nuniverse, think in terms of energy, \r\nfrequency and vibration. \r\nAZ QUOTES \r\n", "ErrorMessage"=>"", "ErrorDetails"=>""}]
@@ -47,9 +61,8 @@ puts result.text_data #Clean result
47
61
  #To convert images from file upload
48
62
 
49
63
  ```ruby
50
- require 'ocr_space'
51
64
 
52
- result = OcrSpace::FromFile.new(apikey: "YOUR API KEY", files: "/Users/suyesh/Desktop/nicola_tesla.jpg")
65
+ result = resource.convert file: "/Users/suyesh/Desktop/nicola_tesla.jpg"
53
66
 
54
67
  puts result.data #Raw result
55
68
 
@@ -63,27 +76,13 @@ puts result.text_data #Clean result
63
76
 
64
77
  #COMMAND LINE INTERFACE ***BONUS***
65
78
 
66
- You can run ocr_space through shell to get quick result from a image using filepath
79
+ You can run ocr_space through shell to get quick result from a image using filepath or url
67
80
 
68
81
  ```
69
82
  $ ocrspace /Users/suyesh/Desktop/nicola_tesla.jpg
70
83
 
71
84
  => If you want to find the secrets of the universe, think in terms of energy, frequency and vibration. AZ QUOTES
72
85
 
73
- ```
74
- #NOTE
75
- For commandline interface to work you will have to set ENV variable 'ocr_api_key' to your apikey.
76
-
77
- ```
78
- $ export ocr_api_key='YOUR API KEY'
79
- ```
80
- Also if you set env variable then you don't need to include apikey in your ruby scripts. You can just do the following -
81
-
82
- ```ruby
83
- result = OcrSpace::FromFile.new(files: "./nicola_tesla.jpg") #for File based
84
-
85
- result = OcrSpace::FromUrl.new(url: "http://bit.ly/2ih9aXt") #for URL based
86
-
87
86
  ```
88
87
 
89
88
  #Optional
data/exe/ocrspace CHANGED
@@ -1,13 +1,14 @@
1
1
  # !/usr/bin/env ruby
2
2
  require 'colorize'
3
3
 
4
- require_relative "../lib/ocr_space/from_file"
4
+ require_relative "../lib/ocr_space/convert"
5
5
 
6
6
  if ARGV.empty?
7
7
  puts "You need to mention the image path".colorize(:red)
8
8
  else
9
9
  begin
10
- result = OcrSpace::FromFile.new(files: ARGV[0])
10
+ resource = OcrSpace::Resource.new
11
+ result = resource.convert file: ARGV[0]
11
12
  puts result.text_data.colorize(:orange)
12
13
  rescue
13
14
  puts "Something went wrong, Please try again.".colorize(:red)
data/lib/ocr_space.rb CHANGED
@@ -1,4 +1,19 @@
1
1
  require 'ocr_space/version'
2
- require 'ocr_space/from_url'
3
- require 'ocr_space/from_file'
2
+ require 'ocr_space/convert'
4
3
  require 'ocr_space/banner'
4
+
5
+ module OcrSpace
6
+ class Resource
7
+ attr_reader :data
8
+
9
+ include OcrSpace::Convert
10
+
11
+ def initialize(apikey: ENV['ocr_api_key'])
12
+ @api_key = apikey
13
+ end
14
+
15
+ def text_data
16
+ data[0]['ParsedText'].delete("\n").delete("\r").strip
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'ocr_space/file_post'
2
+
3
+ module OcrSpace
4
+ module Convert
5
+ def convert(apikey: @api_key, language: 'eng', isOverlayRequired: false, file: nil, url: nil)
6
+ if file
7
+ @files = File.new(file)
8
+ @data = OcrSpace::FilePost.post('/parse/image',
9
+ body: { apikey: apikey,
10
+ language: language,
11
+ isOverlayRequired: isOverlayRequired,
12
+ file: @files })
13
+ @data = @data.parsed_response['ParsedResults']
14
+ elsif url
15
+ @data = HTTParty.post('https://api.ocr.space/parse/image',
16
+ body: { apikey: apikey,
17
+ language: language,
18
+ isOverlayRequired: isOverlayRequired,
19
+ url: url })
20
+ @data = @data.parsed_response['ParsedResults']
21
+ else
22
+ "You need to Pass either file or url."
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module OcrSpace
2
- VERSION = '1.0'.freeze
2
+ VERSION = '2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocr_space
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suyesh Bhandari
@@ -114,9 +114,8 @@ files:
114
114
  - exe/ocrspace
115
115
  - lib/ocr_space.rb
116
116
  - lib/ocr_space/banner.rb
117
+ - lib/ocr_space/convert.rb
117
118
  - lib/ocr_space/file_post.rb
118
- - lib/ocr_space/from_file.rb
119
- - lib/ocr_space/from_url.rb
120
119
  - lib/ocr_space/version.rb
121
120
  - ocr_space.gemspec
122
121
  homepage: https://github.com/suyesh/ocr_space
@@ -1,20 +0,0 @@
1
- require 'ocr_space/file_post'
2
-
3
- module OcrSpace
4
- class File
5
- attr_reader :data
6
- def initialize(apikey: ENV['ocr_api_key'], language: 'eng', isOverlayRequired: false, file: nil)
7
- @files = File.new(file)
8
- @data = OcrSpace::FilePost.post('/parse/image',
9
- body: { apikey: apikey,
10
- language: language,
11
- isOverlayRequired: isOverlayRequired,
12
- file: @files })
13
- @data = @data.parsed_response['ParsedResults']
14
- end
15
-
16
- def text_data
17
- data[0]['ParsedText'].delete("\n").delete("\r").strip
18
- end
19
- end
20
- end
@@ -1,19 +0,0 @@
1
- require 'httparty'
2
-
3
- module OcrSpace
4
- class Url
5
- attr_reader :data
6
- def initialize(apikey: ENV['ocr_api_key'], language: 'eng', isOverlayRequired: false, url: nil, ocr_space: 'https://api.ocr.space/parse/image')
7
- @data = HTTParty.post(ocr_space,
8
- body: { apikey: apikey,
9
- language: language,
10
- isOverlayRequired: isOverlayRequired,
11
- url: url })
12
- @data = @data.parsed_response['ParsedResults']
13
- end
14
-
15
- def text_data
16
- data[0]['ParsedText'].delete("\n").delete("\r").strip
17
- end
18
- end
19
- end