Class: KpApi::Top

Inherits:
Agent
  • Object
show all
Defined in:
lib/kp_api/top.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Agent

#arr_data, #bool_data, #current_page, #data, #data2, #dn, #film_hash, #int_data, #json, #json2, #min_data, #next_page, #page_count, #people_hash, #s2a, #status, #status2, #str_data, #time_data, #url_data, #year_data

Constructor Details

#initialize(top_list = nil) ⇒ Top

Returns a new instance of Top.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kp_api/top.rb', line 5

def initialize(top_list=nil)
  if !top_list.nil? && !METHODS[:get_top][:types][top_list].nil?
    @type       = METHODS[:get_top][:types][top_list]
    @page       = 1
    gen_url
    @json       = json
    @page_count = @json['pagesCount']
    @all        = nil
  else
    #todo
    raise ArgumentError
  end
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/kp_api/top.rb', line 3

def url
  @url
end

Instance Method Details

#ids_all(limit = 15) ⇒ Object



40
41
42
# File 'lib/kp_api/top.rb', line 40

def ids_all(limit=15)
  view_all(limit).map{|film| film[:id]}
end

#viewObject



19
20
21
22
23
# File 'lib/kp_api/top.rb', line 19

def view
  @json['items'].map do |film|
    film_hash(film,'id')
  end
end

#view_all(limit = 15) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kp_api/top.rb', line 25

def view_all(limit=15)
  if @all.nil?
    all = view
    while @page <= limit && next_page
      all += @json['items'].map do |film|
        film_hash(film,'id')
      end
    end
    @all = all
    @all
  else
    @all
  end
end