Class: UpnpContentExplorer::Explorer
- Inherits:
-
Object
- Object
- UpnpContentExplorer::Explorer
- Defined in:
- lib/upnp_content_explorer/explorer.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ root_id: 0 }
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(service, options = {}) ⇒ Explorer
constructor
A new instance of Explorer.
- #root_path ⇒ Object
- #scrape(path) ⇒ Object
Constructor Details
#initialize(service, options = {}) ⇒ Explorer
Returns a new instance of Explorer.
19 20 21 22 23 |
# File 'lib/upnp_content_explorer/explorer.rb', line 19 def initialize(service, = {}) @options = DEFAULT_OPTIONS.merge() @service = service @root = load_root_node(@options[:root_id]) end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
13 14 15 |
# File 'lib/upnp_content_explorer/explorer.rb', line 13 def root @root end |
Instance Method Details
#get(path) ⇒ Object
25 26 27 |
# File 'lib/upnp_content_explorer/explorer.rb', line 25 def get(path) find_terminal_node(prepare_path(path)) end |
#root_path ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/upnp_content_explorer/explorer.rb', line 29 def root_path path = [] current = @root while !current.nil? && current.id != Node::ROOT_ID path << current.title current = load_root_node(current.parent_id) end '/' << path.reverse.join('/') end |
#scrape(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/upnp_content_explorer/explorer.rb', line 41 def scrape(path) node = find_terminal_node(prepare_path(path)) child_items = node.children.map do |child| scrape("#{path}/#{child.title}") end all_items = [] all_items += node.items all_items += child_items.flatten end |