Class: Dribble::Shots

Inherits:
Object show all
Defined in:
lib/dribble/shots.rb

Direct Known Subclasses

Debuts, Everyones, Following, Popular

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shots, attributes = {}) ⇒ Shots

Returns a new instance of Shots.



5
6
7
8
9
10
11
12
13
# File 'lib/dribble/shots.rb', line 5

def initialize(shots, attributes={})
  @shots        = shots
  @page         = attributes[:page]
  @pages        = attributes[:pages]
  @per_page     = attributes[:per_page]
  @total        = attributes[:total]
  @player_name  = attributes[:player_name] || nil
  @api_endpoint = self.class.to_s.split('::').last.downcase.to_sym
end

Instance Attribute Details

#api_endpointObject (readonly)

Returns the value of attribute api_endpoint.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def api_endpoint
  @api_endpoint
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def pages
  @pages
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def per_page
  @per_page
end

#player_nameObject (readonly)

Returns the value of attribute player_name.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def player_name
  @player_name
end

#shotsObject (readonly)

Returns the value of attribute shots.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def shots
  @shots
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/dribble/shots.rb', line 3

def total
  @total
end

Instance Method Details

#next_pageObject

Next Page

Returns:

Raises:



35
36
37
38
39
# File 'lib/dribble/shots.rb', line 35

def next_page
  options       = {:page => self.page.to_i + 1}
  raise Dribble::NoMorePagesAvailable.new('You are already on the last page.') if options[:page] > self.pages.to_i
  send_request(options)
end

#paginate(options) ⇒ Object

Paginate

Parameters:

  • {:page (Hash)

    > 3, :per_page => 15}

Returns:

Raises:



49
50
51
52
# File 'lib/dribble/shots.rb', line 49

def paginate(options)
  raise Dribble::NoMorePagesAvailable.new('You are already on the last page.') if options[:page] > self.pages.to_i
  send_request(options)
end

#prev_pageObject

Previous Page

Returns:

Raises:



22
23
24
25
26
# File 'lib/dribble/shots.rb', line 22

def prev_page
  options       = {:page => self.page.to_i - 1}
  raise Dribble::NoMorePagesAvailable.new('You are already on the first page.') if options[:page] <= 0
  send_request(options)
end