Class: Pecorb::Pager
- Inherits:
-
Object
- Object
- Pecorb::Pager
- Defined in:
- lib/pecorb/pager.rb
Instance Method Summary collapse
- #down ⇒ Object
- #filter!(filter_text) ⇒ Object
-
#initialize(items, viewport_size) ⇒ Pager
constructor
A new instance of Pager.
- #items=(new_items) ⇒ Object
- #items_in_viewport ⇒ Object
- #selected_item ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(items, viewport_size) ⇒ Pager
Returns a new instance of Pager.
5 6 7 8 9 10 |
# File 'lib/pecorb/pager.rb', line 5 def initialize(items, ) @configured_items = @items = items @viewport_size = @cursor = 0 end |
Instance Method Details
#down ⇒ Object
30 31 32 |
# File 'lib/pecorb/pager.rb', line 30 def down move_cursor_by(1) end |
#filter!(filter_text) ⇒ Object
20 21 22 |
# File 'lib/pecorb/pager.rb', line 20 def filter!(filter_text) self.items = fuzzy_filter(filter_text) end |
#items=(new_items) ⇒ Object
24 25 26 27 28 |
# File 'lib/pecorb/pager.rb', line 24 def items=(new_items) @items = new_items @cursor = @cursor.clamp(0, @items.size-1) end |
#items_in_viewport ⇒ Object
16 17 18 |
# File 'lib/pecorb/pager.rb', line 16 def @items.slice(@viewport.min, @viewport_size) end |
#selected_item ⇒ Object
12 13 14 |
# File 'lib/pecorb/pager.rb', line 12 def selected_item @items.fetch(@cursor) end |
#up ⇒ Object
34 35 36 |
# File 'lib/pecorb/pager.rb', line 34 def up move_cursor_by(-1) end |