Class: Tributary::Stream
- Inherits:
-
Object
- Object
- Tributary::Stream
- Defined in:
- lib/tributary/stream.rb
Instance Method Summary collapse
-
#initialize(root = App.root, plugins = App.plugins) ⇒ Stream
constructor
A new instance of Stream.
- #langs ⇒ Object
- #pick_item(path) ⇒ Object
- #previous(item, filter = {}) ⇒ Object
- #recent(limit = nil, filter = {}) ⇒ Object
- #subsequent(item, filter = {}) ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(root = App.root, plugins = App.plugins) ⇒ Stream
Returns a new instance of Stream.
3 4 5 6 7 8 |
# File 'lib/tributary/stream.rb', line 3 def initialize root = App.root, plugins = App.plugins @items = Dir["#{root}/*/*.md"].map { |file| Item.new file } plugins.each do |plugin| @items.each { |item| item.extend plugin } end end |
Instance Method Details
#langs ⇒ Object
10 11 12 |
# File 'lib/tributary/stream.rb', line 10 def langs @items.map(&:lang).uniq.compact.sort end |
#pick_item(path) ⇒ Object
14 15 16 17 |
# File 'lib/tributary/stream.rb', line 14 def pick_item path path, lang = path.split '.' (lang ? @items.select { |item| item.lang == lang } : @items).sort.find { |item| item.path == path } end |
#previous(item, filter = {}) ⇒ Object
19 20 21 |
# File 'lib/tributary/stream.rb', line 19 def previous item, filter = {} published(filter)[published(filter).index { |i| i.path == item.path } + 1] rescue nil end |
#recent(limit = nil, filter = {}) ⇒ Object
23 24 25 |
# File 'lib/tributary/stream.rb', line 23 def recent limit = nil, filter = {} published(filter).take limit || @items.size end |
#subsequent(item, filter = {}) ⇒ Object
27 28 29 |
# File 'lib/tributary/stream.rb', line 27 def subsequent item, filter = {} published(filter).reverse[published(filter).reverse.index { |i| i.path == item.path } + 1] rescue nil end |
#types ⇒ Object
31 32 33 |
# File 'lib/tributary/stream.rb', line 31 def types @items.map(&:type).uniq.sort end |