Class: Spotify::Subscribers

Inherits:
Struct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/spotify/structs/subscribers.rb

Overview

Spotify::Struct for Subscribers of a Playlist.

Memory looks like this:

00 00 00 00 <- count of subscribers
00 00 00 00 <- pointer to subscriber 1
…… …… …… ……
00 00 00 00 <- pointer to subscriber n

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

enclosing_module, #to_h, #to_s

Methods included from TypeSafety

#to_native, #type_class

Constructor Details

#initialize(pointer_or_count) ⇒ Subscribers

Redefined, as the layout of the Struct can only be determined at run-time.

Parameters:

  • pointer_or_count (FFI::Pointer, Integer)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/spotify/structs/subscribers.rb', line 36

def initialize(pointer_or_count)
  count = if pointer_or_count.is_a?(FFI::Pointer)
    if pointer_or_count.null?
      0
    else
      pointer_or_count.read_uint
    end
  else
    pointer_or_count
  end

  layout  = [:count, :uint]
  layout += [:subscribers, [UTF8StringPointer, count]]

  if pointer_or_count.is_a?(FFI::Pointer)
    super(pointer_or_count, *layout)
  else
    super(nil, *layout)
    self[:count] = count
  end
end

Instance Attribute Details

#count=(value) ⇒ Fixnum

Returns the newly set value.

Parameters:

  • value (Fixnum)

    the value to set the attribute count to.

Returns:

  • (Fixnum)

    the newly set value



12
13
14
# File 'lib/spotify/structs/subscribers.rb', line 12

def count=(value)
  @count = value
end

#subscribersArray<Pointer<String>>

Returns the current value of subscribers.

Returns:

  • (Array<Pointer<String>>)

    the current value of subscribers



12
13
14
# File 'lib/spotify/structs/subscribers.rb', line 12

def subscribers
  @subscribers
end

Class Method Details

.release(pointer) ⇒ Object

Releases the given subscribers structure if it is not null.

Parameters:

  • pointer (FFI::Pointer)

    pointing to a subscribers struct



19
20
21
22
23
24
25
26
# File 'lib/spotify/structs/subscribers.rb', line 19

def release(pointer)
  unless pointer.null?
    Spotify.performer.async do
      Spotify.log "Spotify.playlist_subscribers_free(#{pointer})"
      Spotify.playlist_subscribers_free(pointer)
    end
  end
end

Instance Method Details

#each {|subscriber| ... } ⇒ Object

Yields every subscriber as a UTF8-encoded string.

Yields:

  • (subscriber)

Yield Parameters:

  • subscriber (String)


62
63
64
65
# File 'lib/spotify/structs/subscribers.rb', line 62

def each
  return enum_for(__method__) { count } unless block_given?
  count.times { |index| yield self[:subscribers][index] }
end