sane-ffi 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sane/api.rb +3 -1
- data/lib/sane/device.rb +8 -8
- data/lib/sane/version.rb +1 -1
- metadata +1 -1
data/lib/sane/api.rb
CHANGED
@@ -2,7 +2,9 @@ class Sane
|
|
2
2
|
module API
|
3
3
|
extend FFI::Library
|
4
4
|
|
5
|
-
|
5
|
+
lib_paths = Array(ENV["SANE_LIB"] || Dir["/{opt,usr}/{,local/}lib{,64}/libsane.{1.dylib,so.1*}"])
|
6
|
+
fallback_names = %w(libsane.1.dylib libsane.so.1 sane1.dll)
|
7
|
+
ffi_lib(lib_paths + fallback_names)
|
6
8
|
|
7
9
|
enum :status, [:good, 0, :unsupported, :cancelled, :device_busy, :inval, :eof, :jammed, :no_docs, :cover_open, :io_error, :no_mem, :access_denied]
|
8
10
|
enum :value_type, [:bool, 0, :int, :fixed, :string, :button, :group]
|
data/lib/sane/device.rb
CHANGED
@@ -93,11 +93,11 @@ class Sane
|
|
93
93
|
option_count.times.map do |i|
|
94
94
|
begin
|
95
95
|
self[i]
|
96
|
-
rescue Error =>
|
97
|
-
if
|
96
|
+
rescue Error => exception
|
97
|
+
if exception.status == :inval
|
98
98
|
nil # we can't read values of some options (i.e. buttons), ignore them
|
99
99
|
else
|
100
|
-
raise
|
100
|
+
raise exception
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -107,11 +107,6 @@ class Sane
|
|
107
107
|
Hash[*option_names.zip(option_values).flatten]
|
108
108
|
end
|
109
109
|
|
110
|
-
def option_lookup(option_name)
|
111
|
-
return option_name if (0..option_count).include?(option_name)
|
112
|
-
option_descriptors.index { |option| option[:name] == option_name.to_s } or raise(ArgumentError, "Option not found: #{option_name}")
|
113
|
-
end
|
114
|
-
|
115
110
|
def describe(option)
|
116
111
|
option_descriptors[option_lookup(option)]
|
117
112
|
end
|
@@ -122,6 +117,11 @@ class Sane
|
|
122
117
|
|
123
118
|
private
|
124
119
|
|
120
|
+
def option_lookup(option_name)
|
121
|
+
return option_name if (0..option_count).include?(option_name)
|
122
|
+
option_descriptors.index { |option| option[:name] == option_name.to_s } or raise(ArgumentError, "Option not found: #{option_name}")
|
123
|
+
end
|
124
|
+
|
125
125
|
def ensure_closed!
|
126
126
|
raise("Device is already open") if open?
|
127
127
|
end
|
data/lib/sane/version.rb
CHANGED