Class: Glyr::Providers

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/glyr/providers.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ Providers

Returns a new instance of Providers.



34
35
36
# File 'lib/glyr/providers.rb', line 34

def initialize (pointer)
	@internal = pointer.is_a?(FFI::Pointer) ? C::FetcherInfo.new(pointer) : pointer
end

Class Method Details

.createObject



14
15
16
17
18
# File 'lib/glyr/providers.rb', line 14

def self.create
	pointer = C.glyr_info_get

	wrap(pointer)
end

.finalizer(pointer) ⇒ Object



26
27
28
29
30
# File 'lib/glyr/providers.rb', line 26

def self.finalizer (pointer)
	proc {
		C.glyr_info_free(pointer)
	}
end

.wrap(pointer) ⇒ Object



20
21
22
23
24
# File 'lib/glyr/providers.rb', line 20

def self.wrap (pointer)
	new(pointer).tap {|x|
		ObjectSpace.define_finalizer x, finalizer(pointer)
	}
end

Instance Method Details

#[](name) ⇒ Object



48
49
50
# File 'lib/glyr/providers.rb', line 48

def [] (name)
	find { |p| p.name == name || p.type == name }
end

#each(&block) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/glyr/providers.rb', line 38

def each (&block)
	current = @internal

	until current.null?
		block.call(Provider.new(current, self))

		current = C::FetcherInfo.new(current[:next])
	end
end

#to_hashObject



52
53
54
# File 'lib/glyr/providers.rb', line 52

def to_hash
	Hash[map { |p| [p.to_sym, p] }]
end

#to_nativeObject



56
57
58
# File 'lib/glyr/providers.rb', line 56

def to_native
	@internal
end