Class: Plex::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/plex-ruby/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, node) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • object

    representing the parent of what we’re trying to parse

  • nokogiri (Nokogiri::XML::Element)

    node to parse



8
9
10
11
# File 'lib/plex-ruby/parser.rb', line 8

def initialize(parent, node)
  @parent = parent
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/plex-ruby/parser.rb', line 4

def node
  @node
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/plex-ruby/parser.rb', line 4

def parent
  @parent
end

Instance Method Details

#parseArray, ...

Parses a XML node and returns the structure it represents. This is currently used to parse Sections as we don’t know whether a Section holds a list of Shows or a list of Movies. The parsing is done recursively.

Returns:

  • (Array, Movie, Episode, Show)

    depending on what node it is given, will return an Array of Movies or Shows, a single Movie, and single Episode, or a single Show



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/plex-ruby/parser.rb', line 20

def parse
  case node.name
  when 'document'
    Plex::Parser.new(parent, node.root).parse
  when 'MediaContainer'
    parse_media_container
  when 'Video'
    parse_video
  when 'Directory'
    parse_directory
  when 'text'
    nil
  else
  end
end