Class: Admission::Index
- Inherits:
-
Object
- Object
- Admission::Index
- Defined in:
- lib/admission/index.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #add(*add_items, **add_children) ⇒ Object
- #include?(*path) ⇒ Boolean
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #to_list ⇒ Object
Constructor Details
#initialize ⇒ Index
Returns a new instance of Index.
5 6 7 8 |
# File 'lib/admission/index.rb', line 5 def initialize @items = [] @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
3 4 5 |
# File 'lib/admission/index.rb', line 3 def children @children end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/admission/index.rb', line 3 def items @items end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
35 36 37 38 39 40 41 42 |
# File 'lib/admission/index.rb', line 35 def == other case other when Array to_list.eql? other else super end end |
#add(*add_items, **add_children) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/admission/index.rb', line 10 def add *add_items, **add_children @items |= add_items.flatten.map(&:to_sym) add_children.each do |key, list| child = @children[key] || Admission::Index.new child.add *list children[key] = child end self end |
#include?(*path) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/admission/index.rb', line 22 def include? *path item, *path = path item = item.to_sym if path.empty? items.include? item else child = children[item] child ? child.include?(*path) : false end end |
#to_list ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/admission/index.rb', line 45 def to_list result_list = items.dup unless children.empty? result_children = children.inject Hash.new do |h, (key, index)| h[key] = index.to_list h end result_list.push result_children end result_list end |