Class: Hyphae::SiteNode

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

Overview

Site content node, all other site node classes inherit from this one

Direct Known Subclasses

SiteDir, SiteLink, SitePage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, parent = nil) ⇒ SiteNode

Returns a new instance of SiteNode.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hyphae.rb', line 32

def initialize(filename, parent=nil)
  @name = File.basename(filename, '.*')
  @parent = parent
  @hidden = false
  @order = nil
  @date = nil
  if captures = @name.match(/^_(.+)/) then
    @hidden = true
    @name = captures[1]
  elsif captures = @name.match(/^o(\d+)_(.+)/) then
    @order = captures[1].to_i
    @name = captures[2]
  elsif captures = @name.match(/^ut(\d+)_(.+)/) then
    @date = Time.at(captures[1].to_i)
    @name = captures[2]
  end
  @slug = Hyphae::sanitize @name
  @path = @parent ? @parent.path + [(@slug)] : []
  return self
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



30
31
32
# File 'lib/hyphae.rb', line 30

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/hyphae.rb', line 30

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



30
31
32
# File 'lib/hyphae.rb', line 30

def order
  @order
end

#parentObject (readonly)

Returns the value of attribute parent.



30
31
32
# File 'lib/hyphae.rb', line 30

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



30
31
32
# File 'lib/hyphae.rb', line 30

def path
  @path
end

#slugObject (readonly)

Returns the value of attribute slug.



30
31
32
# File 'lib/hyphae.rb', line 30

def slug
  @slug
end

Instance Method Details

#cmp(other) ⇒ Object

Compare this SiteNode with another



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hyphae.rb', line 60

def cmp(other)
  if other.order then
    return 1 if @order.nil?
    return @order <=> other.order
  end
  if other.date then
    return 1 if @date.nil?
    return other.date <=> @date
  end
  @name <=> other.name
end

#rootObject

Get the root SiteNode of a tree of SiteNodes



54
55
56
57
# File 'lib/hyphae.rb', line 54

def root
  return self if @parent.nil?
  @parent.root
end