Class: Depth::RouteElement
- Inherits:
-
Object
- Object
- Depth::RouteElement
- Defined in:
- lib/depth/route_element.rb
Instance Attribute Summary collapse
-
#key_or_index ⇒ Object
(also: #key, #index)
readonly
Returns the value of attribute key_or_index.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(key_or_index, type: :hash) ⇒ RouteElement
constructor
A new instance of RouteElement.
Constructor Details
#initialize(key_or_index, type: :hash) ⇒ RouteElement
Returns a new instance of RouteElement.
6 7 8 9 |
# 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 |
Instance Attribute Details
#key_or_index ⇒ Object (readonly) Also known as: key, index
Returns the value of attribute key_or_index.
3 4 5 |
# File 'lib/depth/route_element.rb', line 3 def key_or_index @key_or_index end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/depth/route_element.rb', line 3 def type @type end |
Class Method Details
.convert(el) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
16 17 18 |
# File 'lib/depth/route_element.rb', line 16 def convert_route(route_array) Array(route_array).map { |el| convert(el) } end |
Instance Method Details
#create ⇒ Object
11 12 13 |
# File 'lib/depth/route_element.rb', line 11 def create { hash: {}, array: [], leaf: nil }.fetch(type, nil) end |