Class: Rockbox::Api::Browse

Inherits:
Object
  • Object
show all
Defined in:
lib/rockbox/api/browse.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Browse

Returns a new instance of Browse.



8
9
10
# File 'lib/rockbox/api/browse.rb', line 8

def initialize(http)
  @http = http
end

Instance Method Details

#directories(path = nil) ⇒ Object



22
23
24
# File 'lib/rockbox/api/browse.rb', line 22

def directories(path = nil)
  entries(path).select { |e| Rockbox.directory?(e) }
end

#entries(path = nil) ⇒ Array<Rockbox::Entry>

Parameters:

  • path (String, nil) (defaults to: nil)

    absolute path; nil for the music root.

Returns:



14
15
16
17
18
19
20
# File 'lib/rockbox/api/browse.rb', line 14

def entries(path = nil)
  data = @http.execute(
    "query Browse($path: String) { treeGetEntries(path: $path) { name attr timeWrite customaction displayName } }",
    path ? { path: path } : nil
  )
  Array(data[:tree_get_entries]).map { |e| Entry.from_hash(e) }
end

#files(path = nil) ⇒ Object



26
27
28
# File 'lib/rockbox/api/browse.rb', line 26

def files(path = nil)
  entries(path).reject { |e| Rockbox.directory?(e) }
end