Class: Anilistrb::Medialist
- Inherits:
-
AnilistObj
- Object
- AnilistObj
- Anilistrb::Medialist
- Defined in:
- lib/Anilistrb/Medialist.rb
Instance Attribute Summary collapse
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#dropped ⇒ Object
readonly
Returns the value of attribute dropped.
-
#lists ⇒ Object
readonly
Returns the value of attribute lists.
-
#paused ⇒ Object
readonly
Returns the value of attribute paused.
-
#planning ⇒ Object
readonly
Returns the value of attribute planning.
-
#repeating ⇒ Object
readonly
Returns the value of attribute repeating.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes inherited from AnilistObj
Instance Method Summary collapse
- #build_list(raw) ⇒ Object
- #build_lists ⇒ Object
-
#initialize(json, type) ⇒ Medialist
constructor
A new instance of Medialist.
- #list_to_s(list) ⇒ Object
- #to_s ⇒ Object
Methods inherited from AnilistObj
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
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
5 6 7 |
# File 'lib/Anilistrb/Medialist.rb', line 5 def completed @completed end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
5 6 7 |
# File 'lib/Anilistrb/Medialist.rb', line 5 def current @current end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/Anilistrb/Medialist.rb', line 4 def data @data end |
#dropped ⇒ Object (readonly)
Returns the value of attribute dropped.
5 6 7 |
# File 'lib/Anilistrb/Medialist.rb', line 5 def dropped @dropped end |
#lists ⇒ Object (readonly)
Returns the value of attribute lists.
4 5 6 |
# File 'lib/Anilistrb/Medialist.rb', line 4 def lists @lists end |
#paused ⇒ Object (readonly)
Returns the value of attribute paused.
5 6 7 |
# File 'lib/Anilistrb/Medialist.rb', line 5 def paused @paused end |
#planning ⇒ Object (readonly)
Returns the value of attribute planning.
5 6 7 |
# File 'lib/Anilistrb/Medialist.rb', line 5 def planning @planning end |
#repeating ⇒ Object (readonly)
Returns the value of attribute repeating.
5 6 7 |
# File 'lib/Anilistrb/Medialist.rb', line 5 def repeating @repeating end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/Anilistrb/Medialist.rb', line 4 def type @type end |
#user ⇒ Object (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_lists ⇒ Object
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_s ⇒ Object
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 |