# Class: YARD::Templates::Section

Inherits:
  Array
  - Object
  - Array
  - YARD::Templates::Section
  show all

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.

Since:

- 0.6.0

## Instance Attribute Summary collapse

- #name ⇒ Object

## Instance Method Summary collapse

- #==(other) ⇒ Object
- #[](*args) ⇒ Object
- #any(item) ⇒ Object
- #dup ⇒ Object
- #eql?(other) ⇒ Boolean
- #initialize(name, *args) ⇒ Section constructor

  A new instance of Section.

- #inspect ⇒ Object
- #place(*args) ⇒ Object
- #push(*args) ⇒ Object (also: #<<)
- #to_a ⇒ Object
- #unshift(*args) ⇒ Object

## Constructor Details

### #initialize(name, *args) ⇒ `Section`

Returns a new instance of Section.

Since:

- 0.6.0

    10
    11
    12
    13

    # File 'lib/yard/templates/section.rb', line 10

    def initialize(name, *args)
      self.name = name
      replace(parse_sections(args))
    end

## Instance Attribute Details

### #name ⇒ `Object`

Since:

- 0.6.0

    8
    9
    10

    # File 'lib/yard/templates/section.rb', line 8

    def name
      @name
    end

## Instance Method Details

### #==(other) ⇒ `Object`

Since:

- 0.6.0

    34
    35
    36
    37
    38
    39
    40
    41
    42
    43

    # File 'lib/yard/templates/section.rb', line 34

    def ==(other)
      case other
      when Section
        eql?(other)
      when Array
        to_a == other
      else
        name == other
      end
    end

### #[](*args) ⇒ `Object`

Since:

- 0.6.0

    21
    22
    23
    24
    25
    26
    27
    28

    # File 'lib/yard/templates/section.rb', line 21

    def [](*args)
      if args.first.is_a?(Range) || args.size > 1
        return self.class.new(name, *super(*args))
      elsif args.first.is_a?(Integer)
        return super(*args)
      end
      find {|o| o.name == args.first }
    end

### #any(item) ⇒ `Object`

Since:

- 0.6.0

    74
    75
    76
    77
    78
    79
    80

    # 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 ⇒ `Object`

Since:

- 0.6.0

    15
    16
    17
    18
    19

    # File 'lib/yard/templates/section.rb', line 15

    def dup
      obj = super
      obj.name = name
      obj
    end

### #eql?(other) ⇒ `Boolean`

Returns:

- (`Boolean`)

Since:

- 0.6.0

    30
    31
    32

    # File 'lib/yard/templates/section.rb', line 30

    def eql?(other)
      super(other) && name == other.name
    end

### #inspect ⇒ `Object`

Since:

- 0.6.0

    54
    55
    56
    57
    58

    # File 'lib/yard/templates/section.rb', line 54

    def inspect
      n = name.respond_to?(:path) ? "T('#{name.path}')" : name.inspect
      subsects = empty? ? "" : ", subsections=#{super}"
      "Section(#{n}#{subsects})"
    end

### #place(*args) ⇒ `Object`

Since:

- 0.6.0

    60
    61
    62

    # File 'lib/yard/templates/section.rb', line 60

    def place(*args)
      super(*parse_sections(args))
    end

### #push(*args) ⇒ `Object` Also known as: <<

Since:

- 0.6.0

    45
    46
    47

    # File 'lib/yard/templates/section.rb', line 45

    def push(*args)
      super(*parse_sections(args))
    end

### #to_a ⇒ `Object`

Since:

- 0.6.0

    64
    65
    66
    67
    68
    69
    70
    71
    72

    # 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) ⇒ `Object`

Since:

- 0.6.0

    50
    51
    52

    # File 'lib/yard/templates/section.rb', line 50

    def unshift(*args)
      super(*parse_sections(args))
    end