Class: ReadwiseCurator::CLI::BookPaginator

Inherits:
Object
  • Object
show all
Defined in:
lib/readwise_curator/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#choicesObject (readonly)

Returns the value of attribute choices.



180
181
182
# File 'lib/readwise_curator/cli.rb', line 180

def choices
  @choices
end

#current_pageObject (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_sizeObject (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_pagesObject



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