Class: BlkID::TagIterate
- Inherits:
-
Object
- Object
- BlkID::TagIterate
- Includes:
- Enumerable
- Defined in:
- lib/rblkid/tag_iterate.rb
Instance Method Summary collapse
- #each ⇒ Object
- #finalize ⇒ Object
-
#initialize(dev) ⇒ TagIterate
constructor
A new instance of TagIterate.
- #next ⇒ Object
- #to_ffi ⇒ Object
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
#each ⇒ Object
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 |
#finalize ⇒ Object
49 50 51 |
# File 'lib/rblkid/tag_iterate.rb', line 49 def finalize BlkID::C.blkid_tag_iterate_end(@struct) end |
#next ⇒ Object
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_ffi ⇒ Object
53 54 55 |
# File 'lib/rblkid/tag_iterate.rb', line 53 def to_ffi @struct end |