Class: Ektoplayer::Models::Browser::BrowsableCollection
- Inherits:
-
Object
- Object
- Ektoplayer::Models::Browser::BrowsableCollection
- Includes:
- Enumerable
- Defined in:
- lib/ektoplayer/models/browser.rb
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #enter(index) ⇒ Object
-
#initialize(database, filters, tag_hierarchy) ⇒ BrowsableCollection
constructor
A new instance of BrowsableCollection.
- #reload ⇒ Object
- #tracks(index) ⇒ Object
Constructor Details
#initialize(database, filters, tag_hierarchy) ⇒ BrowsableCollection
Returns a new instance of BrowsableCollection.
57 58 59 60 61 62 |
# File 'lib/ektoplayer/models/browser.rb', line 57 def initialize(database, filters, tag_hierarchy) @database, @tag_hierarchy = database, tag_hierarchy @filters = filters @tag = @tag_hierarchy.shift(1)[0] reload end |
Instance Method Details
#[](*args) ⇒ Object
54 |
# File 'lib/ektoplayer/models/browser.rb', line 54 def [](*args) @contents[*args] end |
#each(&block) ⇒ Object
53 |
# File 'lib/ektoplayer/models/browser.rb', line 53 def each(&block) @contents.each(&block) end |
#empty? ⇒ Boolean
55 |
# File 'lib/ektoplayer/models/browser.rb', line 55 def empty?; @contents.empty? end |
#enter(index) ⇒ Object
83 84 85 86 87 |
# File 'lib/ektoplayer/models/browser.rb', line 83 def enter(index) return :parent if index == 0 return unless @tag BrowsableCollection.new(@database, new_filters(index), @tag_hierarchy) end |
#reload ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ektoplayer/models/browser.rb', line 64 def reload @contents = [PARENT_DIRECTORY] if @tag @contents.concat( @database.select( columns: @tag, filters: @filters, group_by: @tag, order_by: [@tag] + @filters.map { |f| f[:tag] } ).map { |r| r[0] } ) else @contents.concat( @database.select(filters: @filters) ) end end |
#tracks(index) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/ektoplayer/models/browser.rb', line 89 def tracks(index) if not @tag return [] if index == 0 return [ @contents[index] ] else @database.select(filters: new_filters(index)) end end |