Class: ReadwiseCurator::CLI::BookPaginator
- Inherits:
-
Object
- Object
- ReadwiseCurator::CLI::BookPaginator
- Defined in:
- lib/readwise_curator/cli.rb
Instance Attribute Summary collapse
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
Instance Method Summary collapse
- #handle_selection(selection) ⇒ Object
-
#initialize(choices, page_size = 10) ⇒ BookPaginator
constructor
A new instance of BookPaginator.
- #total_pages ⇒ Object
Constructor Details
#initialize(choices, page_size = 10) ⇒ BookPaginator
Returns a new instance of BookPaginator.
182 183 184 185 186 |
# File 'lib/readwise_curator/cli.rb', line 182 def initialize(choices, page_size = 10) @choices = choices || [] @page_size = page_size @current_page = 0 end |
Instance Attribute Details
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
180 181 182 |
# File 'lib/readwise_curator/cli.rb', line 180 def choices @choices end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
180 181 182 |
# File 'lib/readwise_curator/cli.rb', line 180 def current_page @current_page end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
180 181 182 |
# File 'lib/readwise_curator/cli.rb', line 180 def page_size @page_size end |
Instance Method Details
#handle_selection(selection) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/readwise_curator/cli.rb', line 194 def handle_selection(selection) case selection when :prev_page @current_page = [@current_page - 1, 0].max when :next_page @current_page = [@current_page + 1, total_pages - 1].min else return selection # Book selection end nil # Continue pagination end |
#total_pages ⇒ Object
188 189 190 191 192 |
# File 'lib/readwise_curator/cli.rb', line 188 def total_pages return 1 if @choices.empty? (@choices.length.to_f / @page_size).ceil end |