Class: YARD::Templates::Section
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Array
|
|
Instance Chain:
self,
::Array
|
|
Inherits: |
Array
|
Defined in: | lib/yard/templates/section.rb |
Overview
Abstracts the structure for a section and its subsections into an ordered list of sections and subsections.
Class Method Summary
- .new(name, *args) ⇒ Section constructor
Instance Attribute Summary
- #name rw
Instance Method Summary
-
#<<(*args)
Alias for #push.
- #==(other)
- #[](*args)
- #any(item)
- #dup
- #eql?(other) ⇒ Boolean
- #inspect
- #place(*args)
- #push(*args) (also: #<<)
- #to_a
- #unshift(*args)
- #parse_sections(args) private
::Array
- Inherited
#place | Places values before or after another object (by value) in an array. |
Constructor Details
.new(name, *args) ⇒ Section
# File 'lib/yard/templates/section.rb', line 10
def initialize(name, *args) self.name = name replace(parse_sections(args)) end
Instance Attribute Details
#name (rw)
# File 'lib/yard/templates/section.rb', line 8
attr_accessor :name
Instance Method Details
#<<(*args)
Alias for #push.
# File 'lib/yard/templates/section.rb', line 48
alias << push
#==(other)
#[](*args)
#any(item)
# File 'lib/yard/templates/section.rb', line 74
def any(item) find do |section| return section if section == item return section.any(item) unless section.empty? end nil end
#dup
#eql?(other) ⇒ Boolean
#inspect
#parse_sections(args) (private)
# File 'lib/yard/templates/section.rb', line 84
def parse_sections(args) if args.size == 1 && args.first.is_a?(Array) && !args.first.is_a?(Section) args = args.first end sections = [] args.each_with_index do |name, index| case name when Section; sections << name when Array; next else subsections = args[index + 1].is_a?(Array) ? args[index + 1] : [] subsections = [] if subsections.is_a?(Section) sections << Section.new(name, subsections) end end sections end
#place(*args)
# File 'lib/yard/templates/section.rb', line 60
def place(*args) super(*parse_sections(args)) end
#push(*args) Also known as: #<<
# File 'lib/yard/templates/section.rb', line 45
def push(*args) super(*parse_sections(args)) end
#to_a
# File 'lib/yard/templates/section.rb', line 64
def to_a list = [name] unless empty? subsects = [] each {|s| subsects += s.to_a } list << subsects end list end
#unshift(*args)
# File 'lib/yard/templates/section.rb', line 50
def unshift(*args) super(*parse_sections(args)) end