Module: HELPEMA::ZBar

Defined in:
lib/helpema/zbar.rb

Class Method Summary collapse

Class Method Details

.cam(timeout = 3) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/helpema/zbar.rb', line 6

def self.cam(timeout=3)
  raw = ''
  IO.popen('zbarcam --nodisplay --raw --prescale=800x800', 'r') do |io|
    begin
      Timeout.timeout(timeout) do
        raw << io.gets
        while q = io.gets
          break if q=="\n"
          raw << q
        end
        raw.strip!
      end
    rescue Timeout::Error
      raw = nil
      $stderr.puts $!
    ensure
      Process.kill('INT', io.pid)
    end
  end
  raw
end

.screenObject



28
29
30
31
32
33
34
35
36
# File 'lib/helpema/zbar.rb', line 28

def self.screen
  raw = nil
  Dir.mktmpdir do |tmpdir|
    screenshot = File.join(tmpdir, "#{$$}.#{Time.now.to_f}.png")
    system "gnome-screenshot -f #{screenshot}"
    raw = `zbarimg -q --raw #{screenshot}`.strip
  end
  raw
end