class Node

We track folder state as a tree of Node objects.

Attributes

content[RW]
path[RW]

Public Class Methods

from_json(jnode) click to toggle source
# File examples/search_cache.rb, line 163
def self.from_json(jnode)
  path, jcontent = jnode
  Node.new(path, Node.from_json_content(jcontent))
end
from_json_content(jcontent) click to toggle source
# File examples/search_cache.rb, line 174
def self.from_json_content(jcontent)
  if jcontent.is_a? Hash
    map_hash_values(jcontent) { |jchild| Node.from_json jchild }
  else
    jcontent
  end
end
new(path, content) click to toggle source
# File examples/search_cache.rb, line 150
def initialize(path, content)
  # The "original" page (i.e. not the lower-case path)
  @path = path
  # For files, content is a pair (size, modified)
  # For folders, content is a hash of children Nodes, keyed by lower-case file names.
  @content = content
end
to_json_content(content) click to toggle source
# File examples/search_cache.rb, line 167
def self.to_json_content(content)
  if content.is_a? Hash
    map_hash_values(content) { |child| child.to_json }
  else
    content
  end
end

Public Instance Methods

folder?() click to toggle source
# File examples/search_cache.rb, line 157
def folder?()
  @content.is_a? Hash
end
to_json() click to toggle source
# File examples/search_cache.rb, line 160
def to_json()
  [@path, Node.to_json_content(@content)]
end