Class: Sane::API::OptionDescriptor

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/sane/api.rb

Defined Under Namespace

Classes: Range

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



60
# File 'lib/sane/api.rb', line 60

alias method_missing []

Instance Method Details

#constraintObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sane/api.rb', line 62

def constraint
  c = self[:constraint]
  case self[:constraint_type]
  when 0, :none then nil
  when 1, :range
    Range.new *c.read_array_of_int( 3)
  when 2, :word_list
    c[FFI::Type::INT.size].read_array_of_int c.read_int
  when 3, :string_list
    i, r, p = 0, [], nil
    while 0 < (p = c[i].read_pointer).address
      STDERR.puts p.inspect
      r << p.read_string_to_null
      i += FFI::Type::POINTER.size
    end
    r
  end
end

#to_hashObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sane/api.rb', line 81

def to_hash
  {
    :name => self[:name],
    :title => self[:title],
    :desc => self[:desc],
    :type => self[:type],
    :unit => self[:unit],
    :size => self[:size],
    :cap => self[:cap],
    :constraint => constraint
  }
end