Class: Glyr::Sources

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer, provider) ⇒ Sources



18
19
20
21
# File 'lib/glyr/sources.rb', line 18

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

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



16
17
18
# File 'lib/glyr/sources.rb', line 16

def provider
  @provider
end

Instance Method Details

#[](name) ⇒ Object



33
34
35
# File 'lib/glyr/sources.rb', line 33

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

#each(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/glyr/sources.rb', line 23

def each (&block)
  current = @internal

  until current.null?
    block.call(Source.new(current, provider))

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

#to_hashObject



37
38
39
# File 'lib/glyr/sources.rb', line 37

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

#to_nativeObject



41
42
43
# File 'lib/glyr/sources.rb', line 41

def to_native
  @internal
end