Class: Spotify::Subscribers
- 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
-
#count ⇒ Fixnum
writeonly
The newly set value.
-
#subscribers ⇒ Array<Pointer<String>>
The current value of subscribers.
Class Method Summary collapse
-
.release(pointer) ⇒ Object
Releases the given subscribers structure if it is not null.
Instance Method Summary collapse
-
#each {|subscriber| ... } ⇒ Object
Yields every subscriber as a UTF8-encoded string.
-
#initialize(pointer_or_count) ⇒ Subscribers
constructor
Redefined, as the layout of the Struct can only be determined at run-time.
Methods inherited from Struct
enclosing_module, #to_h, #to_s
Methods included from TypeSafety
Constructor Details
#initialize(pointer_or_count) ⇒ Subscribers
Redefined, as the layout of the Struct can only be determined at run-time.
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.
12 13 14 |
# File 'lib/spotify/structs/subscribers.rb', line 12 def count=(value) @count = value end |
#subscribers ⇒ Array<Pointer<String>>
Returns 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.
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.
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 |