Class: Anilistrb::Medialist

Inherits:
AnilistObj show all
Defined in:
lib/Anilistrb/Medialist.rb

Instance Attribute Summary collapse

Attributes inherited from AnilistObj

#attributes

Instance Method Summary collapse

Methods inherited from AnilistObj

#to_snakecase

Constructor Details

#initialize(json, type) ⇒ Medialist

Returns a new instance of Medialist.



7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#completedObject (readonly)

Returns the value of attribute completed.



5
6
7
# File 'lib/Anilistrb/Medialist.rb', line 5

def completed
  @completed
end

#currentObject (readonly)

Returns the value of attribute current.



5
6
7
# File 'lib/Anilistrb/Medialist.rb', line 5

def current
  @current
end

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/Anilistrb/Medialist.rb', line 4

def data
  @data
end

#droppedObject (readonly)

Returns the value of attribute dropped.



5
6
7
# File 'lib/Anilistrb/Medialist.rb', line 5

def dropped
  @dropped
end

#listsObject (readonly)

Returns the value of attribute lists.



4
5
6
# File 'lib/Anilistrb/Medialist.rb', line 4

def lists
  @lists
end

#pausedObject (readonly)

Returns the value of attribute paused.



5
6
7
# File 'lib/Anilistrb/Medialist.rb', line 5

def paused
  @paused
end

#planningObject (readonly)

Returns the value of attribute planning.



5
6
7
# File 'lib/Anilistrb/Medialist.rb', line 5

def planning
  @planning
end

#repeatingObject (readonly)

Returns the value of attribute repeating.



5
6
7
# File 'lib/Anilistrb/Medialist.rb', line 5

def repeating
  @repeating
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/Anilistrb/Medialist.rb', line 4

def type
  @type
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/Anilistrb/Medialist.rb', line 4

def user
  @user
end

Instance Method Details

#build_list(raw) ⇒ Object



35
36
37
38
39
# 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_listsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



52
53
54
# 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_sObject



41
42
43
44
45
46
47
48
49
50
# 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