Class: Hyphae::SiteNode
- Inherits:
-
Object
- Object
- Hyphae::SiteNode
- Defined in:
- lib/hyphae.rb
Overview
Site content node, all other site node classes inherit from this one
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
-
#cmp(other) ⇒ Object
Compare this SiteNode with another.
-
#initialize(filename, parent = nil) ⇒ SiteNode
constructor
A new instance of SiteNode.
-
#root ⇒ Object
Get the root SiteNode of a tree of SiteNodes.
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
#date ⇒ Object (readonly)
Returns the value of attribute date.
30 31 32 |
# File 'lib/hyphae.rb', line 30 def date @date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/hyphae.rb', line 30 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
30 31 32 |
# File 'lib/hyphae.rb', line 30 def order @order end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
30 31 32 |
# File 'lib/hyphae.rb', line 30 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/hyphae.rb', line 30 def path @path end |
#slug ⇒ Object (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 |