class Anilistrb::Medialist
Attributes
completed[R]
current[R]
data[R]
dropped[R]
lists[R]
paused[R]
planning[R]
repeating[R]
type[R]
user[R]
Public Class Methods
new(json, type)
click to toggle source
# File lib/Anilistrb/Medialist.rb, line 7 def initialize(json, type) @data = json @lists = json['lists'] @user = Anilistrb::User.new(json['user']) @type = type @current = [] @planning = [] @completed = [] @dropped = [] @paused = [] @repeating = [] build_lists end
Public Instance Methods
build_list(raw)
click to toggle source
# File lib/Anilistrb/Medialist.rb, line 35 def build_list(raw) list = [] raw['entries'].each { |x| list.push(Anilistrb::Media.new(x['media'])) } list end
build_lists()
click to toggle source
# File lib/Anilistrb/Medialist.rb, line 21 def build_lists @lists.each do |x| case x['name'] when 'Planning' then @planning = build_list(x) when 'Completed' then @completed = build_list(x) when 'Watching' then @current = build_list(x) when 'Reading' then @current = build_list(x) when 'Dropped' then @dropped = build_list(x) when 'Paused' then @paused = build_list(x) when 'Repeating' then @repeating = build_list(x) end end end
list_to_s(list)
click to toggle source
# File lib/Anilistrb/Medialist.rb, line 52 def list_to_s(list) "#{(list.any? ? list.length : 0).to_s.ljust(5, ' ')} item(s)" end
to_s()
click to toggle source
# File lib/Anilistrb/Medialist.rb, line 41 def to_s " Type: #{@type} list for #{@user} Completed: #{list_to_s(@completed)} Current: #{list_to_s(@current)} Dropped: #{list_to_s(@dropped)} Paused: #{list_to_s(@paused)} Planning: #{list_to_s(@planning)} Repeating: #{list_to_s(@repeating)} " end