Class: Noteman::Dropbox::Node
- Inherits:
-
Object
- Object
- Noteman::Dropbox::Node
- Defined in:
- lib/noteman/state.rb
Overview
We track folder state as a tree of Node objects.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #folder? ⇒ Boolean
-
#initialize(path, content) ⇒ Node
constructor
A new instance of Node.
- #to_json ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
32 33 34 |
# File 'lib/noteman/state.rb', line 32 def content @content end |
#path ⇒ Object
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
40 41 42 |
# File 'lib/noteman/state.rb', line 40 def folder?() @content.is_a? Hash end |
#to_json ⇒ Object
43 44 45 |
# File 'lib/noteman/state.rb', line 43 def to_json() [@path, Node.to_json_content(@content)] end |