-
-
Save orthodoc/8840420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.read_barcode_from_image path | |
# Call the barcode reader - and get a response of multiple lines | |
ls = `/usr/bin/zbarimg '#{path}'`.lines | |
# Handle a variety of unexpected responses that we have seen and debugged quickly over time | |
ls = [ls] if ls.is_a?(String) | |
barcodes = [] | |
return barcodes if ls.nil? || ls == 0 | |
# Read the responses and create an array of barcode types, values and potential URLs | |
for l in ls | |
pos = l.index(':') | |
s = [l[0..pos-1], l[pos+1..-1].chomp] | |
url_string = s[1].dup | |
url_string.gsub!(/((https?:\/\/)([-\w]+\.[-\w\.]+)+\w(:\d+)?(\/([-\w\/_\.]*(\?\S+)?)?)*)/, '<a href="\1">\1</a>') | |
includes_url = !s[1].index(/((https?:\/\/)([-\w]+\.[-\w\.]+)+\w(:\d+)?(\/([-\w\/_\.]*(\?\S+)?)?)*)/).nil? | |
barcodes << (s << includes_url << url_string ) | |
end | |
return barcodes | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment