class TTY::Option::Sections

Public Class Methods

new() click to toggle source
# File lib/tty/option/sections.rb, line 15
def initialize
  @sections = []
end

Public Instance Methods

[](name) click to toggle source
# File lib/tty/option/sections.rb, line 19
def [](name)
  @sections.find { |s| s.name == name }
end
add(name, content) click to toggle source
# File lib/tty/option/sections.rb, line 23
def add(name, content)
  @sections << Section.new(name, content)
end
add_after(name, sect_name, sect_content) click to toggle source
# File lib/tty/option/sections.rb, line 31
def add_after(name, sect_name, sect_content)
  @sections.insert(find_index(name) + 1, Section.new(sect_name, sect_content))
end
add_before(name, sect_name, sect_content) click to toggle source
# File lib/tty/option/sections.rb, line 27
def add_before(name, sect_name, sect_content)
  @sections.insert(find_index(name), Section.new(sect_name, sect_content))
end
delete(*names) click to toggle source
# File lib/tty/option/sections.rb, line 39
def delete(*names)
  @sections.delete_if { |s| names.include?(s.name) }
end
each(&block) click to toggle source
# File lib/tty/option/sections.rb, line 43
def each(&block)
  @sections.each(&block)
end
replace(name, content) click to toggle source
# File lib/tty/option/sections.rb, line 35
def replace(name, content)
  self[name].content = content
end

Private Instance Methods

find_index(name) click to toggle source
# File lib/tty/option/sections.rb, line 49
def find_index(name)
  index = @sections.index { |sect| sect.name == name }
  return index if index
  raise ArgumentError, "There is no section named: #{name.inspect}"
end