sane-ffi-denkn 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/sane/api.rb +53 -5
  2. data/lib/sane/version.rb +1 -1
  3. metadata +13 -10
  4. checksums.yaml +0 -7
@@ -11,6 +11,7 @@ class Sane
11
11
  enum :unit, [:none, 0, :pixel, :bit, :mm, :dpi, :percent, :microsecond]
12
12
  enum :action, [:get_value, 0, :set_value, :set_auto]
13
13
  enum :frame, [:gray, :rgb, :red, :green, :blue]
14
+ ConstraintType = enum :none, 0, :range, :word_list, :string_list
14
15
 
15
16
  class Device < FFI::Struct
16
17
  layout :name, :string, :vendor, :string, :model, :string, :type, :string
@@ -26,12 +27,58 @@ class Sane
26
27
  end
27
28
 
28
29
  class OptionDescriptor < FFI::Struct
29
- class ConstraintType < FFI::Union
30
- layout :string_list, :pointer, :word_list, :pointer, :range, :pointer
30
+ class Range < Struct.new(:min, :max, :quant)
31
+ include Comparable
32
+ include Enumerable
33
+ def <=> x
34
+ (min..max) <=> x
35
+ end
36
+
37
+ def include? x
38
+ (min..max).include?( x) and 0 == (x-min) % quant
39
+ end
40
+
41
+ def === x
42
+ x.kind_of?( Numeric) and include?( x)
43
+ end
44
+
45
+ def each
46
+ min.step( max, [1,quant].max)
47
+ end
48
+ end
49
+
50
+ layout :name, :string,
51
+ :title, :string,
52
+ :desc, :string,
53
+ :type, :value_type,
54
+ :unit, :unit,
55
+ :size, :int,
56
+ :cap, :int,
57
+ :constraint_type, ConstraintType,
58
+ :constraint, :pointer
59
+
60
+ alias method_missing []
61
+
62
+ def constraint
63
+ c = self[:constraint]
64
+ case self[:constraint_type]
65
+ when 0, :none then nil
66
+ when 1, :range
67
+ Range.new *c.read_array_of_int( 3)
68
+ when 2, :word_list
69
+ c[FFI::Type::INT.size].read_array_of_int c.read_int
70
+ when 3, :string_list
71
+ i, r, p = 0, [], nil
72
+ while 0 < (p = c[i].read_pointer).address
73
+ STDERR.puts p.inspect
74
+ r << p.read_string_to_null
75
+ i += FFI::Type::POINTER.size
76
+ end
77
+ r
78
+ end
31
79
  end
32
- layout :name, :string, :title, :string, :desc, :string, :type, :value_type, :unit, :unit, :size, :int, :cap, :int, :constraint_type, ConstraintType
33
80
 
34
- def to_hash;
81
+ def to_hash
35
82
  {
36
83
  :name => self[:name],
37
84
  :title => self[:title],
@@ -39,7 +86,8 @@ class Sane
39
86
  :type => self[:type],
40
87
  :unit => self[:unit],
41
88
  :size => self[:size],
42
- :cap => self[:cap]
89
+ :cap => self[:cap],
90
+ :constraint => constraint
43
91
  }
44
92
  end
45
93
  end
@@ -1,3 +1,3 @@
1
1
  class Sane
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,27 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sane-ffi-denkn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jakub Kuźma & Denis Knauf
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
12
+ date: 2015-01-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: ffi
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  description: Scanner Access now Easier
@@ -44,26 +47,26 @@ files:
44
47
  - sane-ffi.gemspec
45
48
  homepage: ''
46
49
  licenses: []
47
- metadata: {}
48
50
  post_install_message:
49
51
  rdoc_options: []
50
52
  require_paths:
51
53
  - lib
52
54
  required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
53
56
  requirements:
54
- - - '>='
57
+ - - ! '>='
55
58
  - !ruby/object:Gem::Version
56
59
  version: '0'
57
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
58
62
  requirements:
59
- - - '>='
63
+ - - ! '>='
60
64
  - !ruby/object:Gem::Version
61
65
  version: '0'
62
66
  requirements: []
63
67
  rubyforge_project:
64
- rubygems_version: 2.0.14
68
+ rubygems_version: 1.8.23
65
69
  signing_key:
66
- specification_version: 4
70
+ specification_version: 3
67
71
  summary: SANE bindings
68
72
  test_files: []
69
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 8255a18377ffb370d20eca17c9188717a0a9d284
4
- data.tar.gz: 800d4c2645f5ba6c63eb7dfb1423f772492b5ab4
5
- SHA512:
6
- metadata.gz: 43aa89dca9001f69f5c3d4bb24f64464da68a6ac8e7eb2f748bdc0aeae8914b5f6ee937dd03b53ff28e7599d4767ef2161e0588a5b7ab4e99ea6e0891e405be2
7
- data.tar.gz: df42360f9cf5f2218a93cb3ce90fc0eb732d8f25a0e12e22b0bed663944dabed0fa5bf6bfd44c1799997a741abdfeb0dd42a7b0812650f08748031c743f2203b