Class: Sane::Device
- Inherits:
-
Object
- Object
- Sane::Device
- Defined in:
- lib/sane/device.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#vendor ⇒ Object
readonly
Returns the value of attribute vendor.
Instance Method Summary collapse
- #[](option) ⇒ Object
- #[]=(option, value) ⇒ Object
- #async ⇒ Object
- #cancel ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #describe(option) ⇒ Object
-
#initialize(options) ⇒ Device
constructor
A new instance of Device.
- #inspect ⇒ Object
- #open ⇒ Object
- #open? ⇒ Boolean
- #option_count ⇒ Object
- #option_descriptors ⇒ Object
- #option_lookup(option_name) ⇒ Object
- #option_names ⇒ Object
- #option_values ⇒ Object
- #options ⇒ Object
- #parameters ⇒ Object
- #read ⇒ Object
- #start ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(options) ⇒ Device
Returns a new instance of Device.
5 6 7 8 9 10 11 |
# File 'lib/sane/device.rb', line 5 def initialize() @name = [:name] @vendor = [:vendor] @model = [:model] @type = [:type] @handle = nil end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/sane/device.rb', line 3 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/sane/device.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/sane/device.rb', line 3 def type @type end |
#vendor ⇒ Object (readonly)
Returns the value of attribute vendor.
3 4 5 |
# File 'lib/sane/device.rb', line 3 def vendor @vendor end |
Instance Method Details
#[](option) ⇒ Object
74 75 76 77 |
# File 'lib/sane/device.rb', line 74 def [](option) ensure_open! Sane.instance.send(:get_option, @handle, option_lookup(option)) end |
#[]=(option, value) ⇒ Object
79 80 81 82 |
# File 'lib/sane/device.rb', line 79 def []=(option, value) ensure_open! Sane.instance.send(:set_option, @handle, option_lookup(option), value) end |
#async ⇒ Object
59 60 61 62 |
# File 'lib/sane/device.rb', line 59 def async ensure_open! Sane.instance.send(:set_io_mode, @handle, true) end |
#cancel ⇒ Object
49 50 51 52 |
# File 'lib/sane/device.rb', line 49 def cancel ensure_open! Sane.instance.send(:cancel, @handle) end |
#close ⇒ Object
33 34 35 36 37 |
# File 'lib/sane/device.rb', line 33 def close ensure_open! Sane.instance.send(:close, @handle) @handle = nil end |
#closed? ⇒ Boolean
13 14 15 |
# File 'lib/sane/device.rb', line 13 def closed? @handle.nil? end |
#describe(option) ⇒ Object
115 116 117 |
# File 'lib/sane/device.rb', line 115 def describe(option) option_descriptors[option_lookup(option)] end |
#inspect ⇒ Object
119 120 121 |
# File 'lib/sane/device.rb', line 119 def inspect %Q{#<#{self.class.name}:"#{name}">} end |
#open ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sane/device.rb', line 21 def open ensure_closed! @handle = Sane.instance.send(:open, @name) if block_given? begin yield(self) ensure close end end end |
#open? ⇒ Boolean
17 18 19 |
# File 'lib/sane/device.rb', line 17 def open? !closed? end |
#option_count ⇒ Object
64 65 66 67 |
# File 'lib/sane/device.rb', line 64 def option_count ensure_open! Sane.instance.send(:get_option, @handle, 0) end |
#option_descriptors ⇒ Object
84 85 86 |
# File 'lib/sane/device.rb', line 84 def option_descriptors option_count.times.map { |i| Sane.instance.send(:get_option_descriptor, @handle, i) } end |
#option_lookup(option_name) ⇒ Object
110 111 112 113 |
# File 'lib/sane/device.rb', line 110 def option_lookup(option_name) return option_name if (0..option_count).include?(option_name) option_descriptors.index { |option| option[:name] == option_name.to_s } or raise(ArgumentError, "Option not found: #{option_name}") end |
#option_names ⇒ Object
88 89 90 |
# File 'lib/sane/device.rb', line 88 def option_names option_descriptors.map { |option| option[:name] } end |
#option_values ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sane/device.rb', line 92 def option_values option_count.times.map do |i| begin self[i] rescue Error => e if e.status == :inval nil # we can't read values of some options (i.e. buttons), ignore them else raise e end end end end |
#options ⇒ Object
106 107 108 |
# File 'lib/sane/device.rb', line 106 def Hash[*option_names.zip(option_values).flatten] end |
#parameters ⇒ Object
69 70 71 72 |
# File 'lib/sane/device.rb', line 69 def parameters ensure_open! Sane.instance.send(:get_parameters, @handle) end |
#read ⇒ Object
44 45 46 47 |
# File 'lib/sane/device.rb', line 44 def read ensure_open! Sane.instance.send(:read, @handle) end |
#start ⇒ Object
39 40 41 42 |
# File 'lib/sane/device.rb', line 39 def start ensure_open! Sane.instance.start(@handle) end |
#sync ⇒ Object
54 55 56 57 |
# File 'lib/sane/device.rb', line 54 def sync ensure_open! Sane.instance.send(:set_io_mode, @handle, false) end |