Class: Aspose::Cloud::Barcode::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/Barcode/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Reader

Returns a new instance of Reader.



5
6
7
8
# File 'lib/Barcode/reader.rb', line 5

def initialize(filename)
  @filename = filename
  raise 'Base file is not specified' if @filename.empty?
end

Instance Method Details

#read(symbology = '', remote_folder = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Read Barcode from Aspose Cloud Storage

@param string symbology Type of barcode.


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/Barcode/reader.rb', line 14

def read(symbology='', remote_folder='', storage_type='Aspose', storage_name='')

    str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/#{@filename}/recognize"
    str_uri = "#{str_uri}?type=#{symbology}" unless symbology.empty?
    str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,remote_folder,storage_name,storage_type)

    signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
    response = RestClient.get(signed_uri, :accept => 'application/json')
    json = JSON.parse(response)
    json['Code'] == 200 ? json['Barcodes'] : nil
end

#read_barcode_count(symbology, barcodesCount) ⇒ Object

Recognize Specified count of Barcodes

@param string symbology Type of barcode.
@param string barcodesCount Recognize specified count of barcodes.


126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/Barcode/reader.rb', line 126

def read_barcode_count(symbology, barcodesCount)
  raise 'Symbology not provided.' if symbology.empty?
  raise 'Barcode count not provided.' if barcodesCount.nil?

  str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/#{@filename}/recognize"
  str_uri = "#{str_uri}?type=#{symbology}&barcodesCount=#{barcodesCount}"

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.get(signed_uri, {:accept => 'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Barcodes'] : nil
end

#read_by_algorithm(symbology, algorithm) ⇒ Object

Read Barcodes by Applying Image Processing Algorithm

@param string symbology Type of barcode.
@param string barcodesCount Recognize specified count of barcodes.


144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/Barcode/reader.rb', line 144

def read_by_algorithm(symbology, algorithm)
  raise 'Symbology not provided.' if symbology.empty?
  raise 'algorithm not provided.' if algorithm.empty?

  str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/#{@filename}/recognize"
  str_uri = "#{str_uri}?type=#{symbology}&BinarizationHints=#{algorithm}"

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.get(signed_uri, {:accept => 'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Barcodes'] : nil
end

#read_from_local_image(local_image, remote_folder = '', symbology = '', format = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Read Barcode from Local Image

@param string local_image Path of the local image.
@param string symbology Type of barcode.
@param string format Returns an image in specified format.


32
33
34
35
36
37
38
39
# File 'lib/Barcode/reader.rb', line 32

def read_from_local_image(local_image, remote_folder='', symbology='', format='', storage_type='Aspose', storage_name='')
    raise 'local image file not provided.' if local_image.empty?

    folder = Aspose::Cloud::AsposeStorage::Folder.new
    folder.upload_file(local_image, remote_folder, storage_type, storage_name)

    readr(File.basename(local_image), remote_folder, symbology, format)
end

#read_from_url(url, symbology) ⇒ Object

Read Barcode from External Image URL

@param string url URL of the image.
@param string symbology Type of barcode.


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/Barcode/reader.rb', line 66

def read_from_url(url, symbology)
  raise 'URL not provided.' if url.empty?
  raise 'Symbology not provided.' if symbology.empty?

  str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/recognize"
  str_uri = "#{str_uri}?type=#{symbology}&url=#{url}"

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.post(signed_uri, '', {:accept => 'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Barcodes'] : nil
end

#read_specific_region(symbology, rectX, rectY, rectWidth, rectHeight) ⇒ Object

Read Barcode from Specific Region of Image

@param string symbology Type of barcode.
@param number rectX X position of rectangle.
@param number rectY Y position of rectangle.
@param number rectWidth Width of rectangle.
@param number rectX Height of rectangle.


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/Barcode/reader.rb', line 87

def read_specific_region(symbology, rectX, rectY, rectWidth, rectHeight)
  raise 'Symbology not provided.' if symbology.empty?
  raise 'X position not provided.' if rectX.nil?
  raise 'Y position not provided.' if rectY.nil?
  raise 'Width not provided.' if rectWidth.nil?
  raise 'Height not provided.' if rectHeight.nil?

  str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/#{@filename}/recognize"
  str_uri = "#{str_uri}?type=#{symbology}&rectX=#{rectX}&rectY=#{rectY}&rectWidth=#{rectWidth}&rectHeight=#{rectHeight}"

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.get(signed_uri, {:accept => 'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Barcodes'] : nil
end

#read_with_checksum(symbology, checksumValidation) ⇒ Object

Recognize Barcode with Checksum Option from Storage

@param string symbology Type of barcode.
@param string checksumValidation Sets checksum validation parameter.


108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/Barcode/reader.rb', line 108

def read_with_checksum(symbology, checksumValidation)
  raise 'Symbology not provided.' if symbology.empty?
  raise 'Checksum not provided.' if checksumValidation.empty?

  str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/#{@filename}/recognize"
  str_uri = "#{str_uri}?type=#{symbology}&checksumValidation=#{checksumValidation}"

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.get(signed_uri, {:accept => 'application/json'})
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Barcodes'] : nil
end

#readr(remote_image_name, remote_folder = '', symbology = '', format = '', storage_type = 'Aspose', storage_name = '') ⇒ Object

Read Barcode from Aspose Cloud Storage

@param string remote_image_name Name of the image.
@param string symbology Type of barcode.
@param string format Returns an image in specified format.


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/Barcode/reader.rb', line 47

def readr(remote_image_name, remote_folder='', symbology='', format='', storage_type='Aspose', storage_name='')
  raise 'remote image file not provided.' if remote_image_name.empty?

  str_uri = "#{Aspose::Cloud::Common::Product.product_uri}/barcode/#{remote_image_name}/recognize"
  str_uri = "#{str_uri}?type=#{symbology}" unless symbology.empty?
  str_uri = "#{str_uri}?format=#{format}" unless format.empty?
  str_uri = Aspose::Cloud::Common::Utils.append_storage(str_uri,remote_folder,storage_name,storage_type)

  signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
  response = RestClient.get(signed_uri, :accept => 'application/json')
  json = JSON.parse(response)
  json['Code'] == 200 ? json['Barcodes'] : nil
end