Class: Paginator
- Inherits:
-
Object
- Object
- Paginator
- Defined in:
- lib/paginator.rb
Overview
this class fetches and paginates the issues from github.com
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #dec ⇒ Object
- #format_issue(issue) ⇒ Object
- #formatted_issues ⇒ Object
- #inc ⇒ Object
-
#initialize(credentials) ⇒ Paginator
constructor
A new instance of Paginator.
- #issues ⇒ Object
- #next? ⇒ Boolean
- #no_issues? ⇒ Boolean
- #prev? ⇒ Boolean
Constructor Details
#initialize(credentials) ⇒ Paginator
Returns a new instance of Paginator.
7 8 9 10 11 12 |
# File 'lib/paginator.rb', line 7 def initialize(credentials) @credentials = credentials @page = 1 @cache = {} @next = {} end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/paginator.rb', line 5 def page @page end |
Instance Method Details
#dec ⇒ Object
42 43 44 |
# File 'lib/paginator.rb', line 42 def dec @page = [@page - 1, 1].max end |
#format_issue(issue) ⇒ Object
34 35 36 |
# File 'lib/paginator.rb', line 34 def format_issue(issue) "#{issue['number']} --- #{issue['title']}" end |
#formatted_issues ⇒ Object
38 39 40 |
# File 'lib/paginator.rb', line 38 def formatted_issues issues.map { |i| format_issue(i) } end |
#inc ⇒ Object
46 47 48 |
# File 'lib/paginator.rb', line 46 def inc @page += 1 end |
#issues ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/paginator.rb', line 14 def issues @cache[@page] ||= begin issues = fetch_issues @next[@page] = issues.count.positive? issues end end |
#next? ⇒ Boolean
26 27 28 |
# File 'lib/paginator.rb', line 26 def next? issues && @next[@page] end |
#no_issues? ⇒ Boolean
22 23 24 |
# File 'lib/paginator.rb', line 22 def no_issues? @page == 1 && issues.empty? end |
#prev? ⇒ Boolean
30 31 32 |
# File 'lib/paginator.rb', line 30 def prev? @page > 1 end |