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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(str, level = 0) ⇒ Path
constructor
A new instance of Path.
- #parent_to_s ⇒ 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 |
# File 'lib/dmoz_sax/path.rb', line 8 def initialize str, level = 0 resource = str.gsub('_', ' ').split(':') @name = resource.first if resource.length == 2 @level = level.to_i unless resource.empty? super(resource.last.split('/')) else super([]) end 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 |
Class Method Details
.normalize(arr) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/dmoz_sax/path.rb', line 33 def self.normalize arr if arr.nil? or arr.length == 0 [] else dup = arr.dup.reject {|a| a =~ /^[A-Z0-9]$/} dup.shift if arr.first == 'Top' dup end end |
.path_str(arr) ⇒ Object
29 30 31 |
# File 'lib/dmoz_sax/path.rb', line 29 def self.path_str arr arr.empty? ? '/' : "/#{ arr.join('/') }" end |