Class: TTY::Option::Sections

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/tty/option/sections.rb

Instance Method Summary collapse

Constructor Details

#initializeSections

Returns a new instance of Sections.



15
16
17
# File 'lib/tty/option/sections.rb', line 15

def initialize
  @sections = []
end

Instance Method Details

#[](name) ⇒ Object



19
20
21
# File 'lib/tty/option/sections.rb', line 19

def [](name)
  @sections.find { |s| s.name == name }
end

#add(name, content) ⇒ Object



23
24
25
# 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) ⇒ Object



31
32
33
# 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) ⇒ Object



27
28
29
# 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) ⇒ Object



39
40
41
# File 'lib/tty/option/sections.rb', line 39

def delete(*names)
  @sections.delete_if { |s| names.include?(s.name) }
end

#each(&block) ⇒ Object



43
44
45
# File 'lib/tty/option/sections.rb', line 43

def each(&block)
  @sections.each(&block)
end

#replace(name, content) ⇒ Object



35
36
37
# File 'lib/tty/option/sections.rb', line 35

def replace(name, content)
  self[name].content = content
end