Class: DmozSax::Path
- Inherits:
-
Array
- Object
- Array
- DmozSax::Path
- Defined in:
- lib/dmoz_sax/path.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(str, level = 0) ⇒ Path
constructor
A new instance of Path.
- #parent_path ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(str, level = 0) ⇒ Path
Returns a new instance of Path.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dmoz_sax/path.rb', line 8 def initialize str, level = 0 resource = str.gsub('_', ' ').split(':') @name = resource.first if resource.length == 2 unless resource.empty? @path = resource.last.split('/').reject {|a| a =~ /^[A-Z0-9]$/} @path.shift if 'Top' == @path.first else @path = [] end @level = level.to_i super(@path.freeze) end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
6 7 8 |
# File 'lib/dmoz_sax/path.rb', line 6 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/dmoz_sax/path.rb', line 6 def name @name end |
Instance Method Details
#parent_path ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dmoz_sax/path.rb', line 31 def parent_path if @path.length == 0 nil else @path[0...-1].join('/') end end |
#to_a ⇒ Object
23 24 25 |
# File 'lib/dmoz_sax/path.rb', line 23 def to_a @path.dup end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/dmoz_sax/path.rb', line 27 def to_s @path.join('/') end |