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, 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.
-
#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.
-
#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 |
#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 |
#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 37 38 39 40 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 32 def next_page return nil if last_page? self.class.new( reinit_endpoint( override_req_params: { page: current_page + 1 } ).do_get ) 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_lokalise_api/collections/base.rb', line 44 def prev_page return nil if first_page? self.class.new( reinit_endpoint( override_req_params: { page: current_page - 1 } ).do_get ) 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 |