class Lookbook::TreeNode

def <=>(other)

def <=>(other)
  if content?
    content <=> (other.content? ? other.content : other)
  else
    [priority, label] <=> [other.priority, other.label]
  end
end

def add_child(name, content = nil, priority: 10000)

def add_child(name, content = nil, priority: 10000)
  children << TreeNode.new("#{path}/#{name}", content, priority: priority)
end

def content?

def content?
  content.present?
end

def content_value(method_name, fallback = nil)

def content_value(method_name, fallback = nil)
  value = content.send(method_name) if content
  value || fallback
end

def depth

def depth
  path.split("/").size
end

def each(&block)

def each(&block)
  if block
    children.sort.each do |child|
      yield child
    end
  else
    to_enum(:each)
  end
end

def get_child(name)

def get_child(name)
  children.find { |child| child.name == name }
end

def has_child?(name)

def has_child?(name)
  !!get_child(name)
end

def id

def id
  Utils.id(content_value(:id, path))
end

def initialize(path = nil, content = nil, priority: 10000)

def initialize(path = nil, content = nil, priority: 10000)
  @path = path.to_s
  @content = content
  @priority = priority
  @children = []
end

def label

def label
  content_value(:label, name.titleize)
end

def name

def name
  segments.last
end

def priority

def priority
  content_value(:priority, @priority)
end

def segments

def segments
  path.split("/")
end

def type

def type
  content_value(:type, :directory)
end