Class: DmozSax::Path

Inherits:
Array
  • Object
show all
Defined in:
lib/dmoz_sax/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#levelObject (readonly)

Returns the value of attribute level.



6
7
8
# File 'lib/dmoz_sax/path.rb', line 6

def level
  @level
end

#nameObject (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_pathObject



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_aObject



23
24
25
# File 'lib/dmoz_sax/path.rb', line 23

def to_a
  @path.dup
end

#to_sObject



27
28
29
# File 'lib/dmoz_sax/path.rb', line 27

def to_s
  @path.join('/')
end