Class: RubyLokaliseApi::Collections::Base
- Inherits:
-
Object
- Object
- RubyLokaliseApi::Collections::Base
- Extended by:
- Forwardable, RubyLokaliseApi::Concerns::AttrsLoadable, Utils::Attributes
- Includes:
- Enumerable, Utils::Keys
- Defined in:
- lib/ruby_lokalise_api/collections/base.rb
Overview
Base collection. Collection is an array of resources. The actual resources can be found by calling the ‘.collection` method
Direct Known Subclasses
Branches, Contributors, CustomTranslationStatuses, Files, KeyComments, Keys, Orders, PaymentCards, PermissionTemplates, ProjectComments, ProjectLanguages, Projects, QueuedProcesses, Screenshots, Segments, Snapshots, SystemLanguages, Tasks, TeamUserGroups, TeamUsers, Teams, TranslationProviders, Translations, Webhooks
Constant Summary collapse
- ATTRS_FILENAME =
'collection_attributes.yml'
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#next_cursor ⇒ Object
readonly
Returns the value of attribute next_cursor.
-
#results_per_page ⇒ Object
readonly
Returns the value of attribute results_per_page.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
-
#total_results ⇒ Object
readonly
Returns the value of attribute total_results.
Instance Method Summary collapse
-
#first_page? ⇒ Boolean
Checks whether the current page is the first one.
-
#initialize(response) ⇒ Base
constructor
A new instance of Base.
-
#last_page? ⇒ Boolean
Checks whether the current page is the last one.
-
#load_next_cursor ⇒ Object
Tries to fetch the next cursor for paginated collection Returns a new collection or nil if the next cursor is not available.
-
#next_cursor? ⇒ Boolean
Checks whether the next cursor is available.
-
#next_page ⇒ Object
Tries to fetch the next page for paginated collection Returns a new collection or nil if the next page is not available.
-
#next_page? ⇒ Boolean
Checks whether the next page is available.
-
#prev_page ⇒ Object
Tries to fetch the previous page for paginated collection Returns a new collection or nil if the previous page is not available.
-
#prev_page? ⇒ Boolean
Checks whether the previous page is available.
Methods included from RubyLokaliseApi::Concerns::AttrsLoadable
Methods included from Utils::Keys
#collection_key_for, #data_key_for
Constructor Details
#initialize(response) ⇒ Base
Returns a new instance of Base.
23 24 25 26 27 28 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 23 def initialize(response) @self_endpoint = response.endpoint populate_common_attrs_from response produce_collection_from response end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
20 21 22 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 20 def collection @collection end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
20 21 22 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 20 def current_page @current_page end |
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
20 21 22 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 20 def next_cursor @next_cursor end |
#results_per_page ⇒ Object (readonly)
Returns the value of attribute results_per_page.
20 21 22 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 20 def results_per_page @results_per_page end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
20 21 22 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 20 def total_pages @total_pages end |
#total_results ⇒ Object (readonly)
Returns the value of attribute total_results.
20 21 22 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 20 def total_results @total_results end |
Instance Method Details
#first_page? ⇒ Boolean
Checks whether the current page is the first one
74 75 76 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 74 def first_page? !prev_page? end |
#last_page? ⇒ Boolean
Checks whether the current page is the last one
62 63 64 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 62 def last_page? !next_page? end |
#load_next_cursor ⇒ Object
Tries to fetch the next cursor for paginated collection Returns a new collection or nil if the next cursor is not available
40 41 42 43 44 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 40 def load_next_cursor return nil unless next_cursor? fetch_cursor(next_cursor) end |
#next_cursor? ⇒ Boolean
Checks whether the next cursor is available
80 81 82 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 80 def next_cursor? !next_cursor.nil? && next_cursor != '' end |
#next_page ⇒ Object
Tries to fetch the next page for paginated collection Returns a new collection or nil if the next page is not available
32 33 34 35 36 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 32 def next_page return nil if last_page? fetch_page(current_page + 1) end |
#next_page? ⇒ Boolean
Checks whether the next page is available
56 57 58 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 56 def next_page? current_page.positive? && current_page < total_pages end |
#prev_page ⇒ Object
Tries to fetch the previous page for paginated collection Returns a new collection or nil if the previous page is not available
48 49 50 51 52 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 48 def prev_page return nil if first_page? fetch_page(current_page - 1) end |
#prev_page? ⇒ Boolean
Checks whether the previous page is available
68 69 70 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 68 def prev_page? current_page > 1 end |