Class: BlkID::TagIterate

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rblkid/tag_iterate.rb

Instance Method Summary collapse

Constructor Details

#initialize(dev) ⇒ TagIterate

Returns a new instance of TagIterate.



26
27
28
29
30
# File 'lib/rblkid/tag_iterate.rb', line 26

def initialize (dev)
  @struct = BlkID::C.blkid_tag_iterate_begin(dev.to_ffi)

  ObjectSpace.define_finalizer(self, method(:finalize))
end

Instance Method Details

#eachObject



40
41
42
43
44
45
46
47
# File 'lib/rblkid/tag_iterate.rb', line 40

def each
  Hash[[].tap {|a|
    while (tag = self.next)
      a << tag
      yield *tag if block_given?
    end
  }]
end

#finalizeObject



49
50
51
# File 'lib/rblkid/tag_iterate.rb', line 49

def finalize
  BlkID::C.blkid_tag_iterate_end(@struct)
end

#nextObject



32
33
34
35
36
37
38
# File 'lib/rblkid/tag_iterate.rb', line 32

def next
  type = FFI::MemoryPointer.new(:string)
  value = FFI::MemoryPointer.new(:string)
  BlkID::C.blkid_tag_next(@struct, type, value)

  [type, value]
end

#to_ffiObject



53
54
55
# File 'lib/rblkid/tag_iterate.rb', line 53

def to_ffi
  @struct
end