Class: YTools::Path::IndexSelector

Inherits:
Selector
  • Object
show all
Defined in:
lib/ytools/path/selectors.rb

Instance Attribute Summary collapse

Attributes inherited from Selector

#subselector

Instance Method Summary collapse

Methods inherited from Selector

#chain, #chained?

Constructor Details

#initialize(index) ⇒ IndexSelector

Returns a new instance of IndexSelector.



48
49
50
# File 'lib/ytools/path/selectors.rb', line 48

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



46
47
48
# File 'lib/ytools/path/selectors.rb', line 46

def index
  @index
end

Instance Method Details

#select(array) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ytools/path/selectors.rb', line 52

def select(array)
  if array.respond_to?(:[])
    value = array[index]
    if chained?
      subselector.select(value)
    else
      value
    end
  else
    nil
  end
end