Class: KpApi::Top
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #ids_all(limit = 15) ⇒ Object
-
#initialize(top_list = nil) ⇒ Top
constructor
A new instance of Top.
- #view ⇒ Object
- #view_all(limit = 15) ⇒ Object
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
#url ⇒ Object
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 |
#view ⇒ Object
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 |