Class: Yt::Resource
- Inherits:
-
Object
- Object
- Yt::Resource
- Defined in:
- lib/yt/resource.rb
Overview
Provides a base class for YouTube channels, videos, playlists and items. This is an abstract class and should not be instantiated directly.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The resource’s data.
Class Method Summary collapse
-
.where(conditions = {}) ⇒ Yt::Relation<Yt::Video>
The videos matching the conditions.
Instance Method Summary collapse
-
#id ⇒ String
The resource’s unique ID.
-
#initialize(data = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#inspect ⇒ String
A representation of the resource instance.
-
#select(*parts) ⇒ Yt::Resource
Specifies which parts of the resource to fetch when hitting the data API.
Constructor Details
#initialize(data = {}) ⇒ Resource
Returns a new instance of Resource.
7 8 9 10 |
# File 'lib/yt/resource.rb', line 7 def initialize(data = {}) @data = data @selected_data_parts = [] end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns the resource’s data.
18 19 20 |
# File 'lib/yt/resource.rb', line 18 def data @data end |
Class Method Details
.where(conditions = {}) ⇒ Yt::Relation<Yt::Video>
Returns the videos matching the conditions.
34 35 36 37 38 39 40 41 |
# File 'lib/yt/resource.rb', line 34 def self.where(conditions = {}) @where ||= Relation.new(self) do || slicing_conditions_every(50) do || fetch resources_path, where_params() end end @where.where conditions end |
Instance Method Details
#id ⇒ String
Returns the resource’s unique ID.
13 14 15 |
# File 'lib/yt/resource.rb', line 13 def id @data[:id] end |
#inspect ⇒ String
Returns a representation of the resource instance.
21 22 23 |
# File 'lib/yt/resource.rb', line 21 def inspect "#<#{self.class} @id=#{id}>" end |
#select(*parts) ⇒ Yt::Resource
Specifies which parts of the resource to fetch when hitting the data API.
28 29 30 31 |
# File 'lib/yt/resource.rb', line 28 def select(*parts) @selected_data_parts = parts self end |