class Depth::RouteElement

Attributes

index[R]
key[R]
key_or_index[R]
type[R]

Public Class Methods

convert(el) click to toggle source
# File lib/depth/route_element.rb, line 20
def convert(el)
  return el if el.is_a?(RouteElement)
  case el
  when Array
    type = el.count > 1 ? el[1] : :hash
    RouteElement.new(el[0], type: type)
  when Hash
    key_or_index = el.fetch(:key) { el.fetch(:index) }
    RouteElement.new(key_or_index, type: el.fetch(:type, :hash))
  else
    RouteElement.new(el)
  end
end
convert_route(route_array) click to toggle source
# File lib/depth/route_element.rb, line 16
def convert_route(route_array)
  Array(route_array).map { |el| convert(el) }
end
new(key_or_index, type: :hash) click to toggle source
# File lib/depth/route_element.rb, line 6
def initialize(key_or_index, type: :hash)
  @key_or_index = key_or_index
  @type = type.to_sym
end

Public Instance Methods

create() click to toggle source
# File lib/depth/route_element.rb, line 11
def create
  { hash: {}, array: [], leaf: nil }.fetch(type, nil)
end