Class: Noteman::Dropbox::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/noteman/state.rb

Overview

We track folder state as a tree of Node objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, content) ⇒ Node

Returns a new instance of Node.



33
34
35
36
37
38
39
# File 'lib/noteman/state.rb', line 33

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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



32
33
34
# File 'lib/noteman/state.rb', line 32

def content
  @content
end

#pathObject

Returns the value of attribute path.



32
33
34
# File 'lib/noteman/state.rb', line 32

def path
  @path
end

Class Method Details

.from_json(jnode) ⇒ Object



46
47
48
49
# File 'lib/noteman/state.rb', line 46

def self.from_json(jnode)
  path, jcontent = jnode
  Node.new(path, Node.from_json_content(jcontent))
end

.from_json_content(jcontent) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/noteman/state.rb', line 57

def self.from_json_content(jcontent)
  if jcontent.is_a? Hash
    map_hash_values(jcontent) { |jchild| Node.from_json jchild }
  else
    jcontent
  end
end

.to_json_content(content) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/noteman/state.rb', line 50

def self.to_json_content(content)
  if content.is_a? Hash
    map_hash_values(content) { |child| child.to_json }
  else
    content
  end
end

Instance Method Details

#folder?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/noteman/state.rb', line 40

def folder?()
  @content.is_a? Hash
end

#to_jsonObject



43
44
45
# File 'lib/noteman/state.rb', line 43

def to_json()
  [@path, Node.to_json_content(@content)]
end