Class: NattyUI::Table::Row

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/natty-ui/table.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **_) ⇒ Object (private)



147
148
149
150
151
152
# File 'lib/natty-ui/table.rb', line 147

def method_missing(name, *args, **_)
  return super unless name.end_with?('=')
  return super unless Cell::Attributes.public_method_defined?(name)
  @cells.each { _1.attributes.__send__(name, *args) }
  args[0]
end

Instance Method Details

#<<(text) ⇒ Row

Add a new cell to the row with given text.

Returns:

  • (Row)

    itself



135
136
137
138
# File 'lib/natty-ui/table.rb', line 135

def <<(text)
  add(text)
  self
end

#[](index) ⇒ Cell?

Returns cell at given index.

Returns:

  • (Cell, nil)

    cell at given index



112
# File 'lib/natty-ui/table.rb', line 112

def [](index) = @cells[index]

#[]=(index, *args) ⇒ Cell

Returns created cell.

Returns:

  • (Cell)

    created cell



115
116
117
118
# File 'lib/natty-ui/table.rb', line 115

def []=(index, *args)
  @cells[index] = create_cell(args)
  @cells.map! { _1 || Cell.new }
end

#add(*text, **attributes) ⇒ Cell

Add a new cell to the row with given text and attributes.

Returns:

  • (Cell)

    created cell



122
123
124
125
126
# File 'lib/natty-ui/table.rb', line 122

def add(*text, **attributes)
  nc = Cell.new(*text, **attributes)
  @cells << nc
  block_given? ? yield(nc) : nc
end

#countInteger

Returns count of cells.

Returns:

  • (Integer)

    count of cells



107
# File 'lib/natty-ui/table.rb', line 107

def count = @cells.size

#delete(cell) ⇒ Object



128
129
130
131
# File 'lib/natty-ui/table.rb', line 128

def delete(cell)
  cell.is_a?(Cell) ? @cells.delete(cell) : @cells.delete_at(cell)
  self
end

#each(&block) ⇒ Object



109
# File 'lib/natty-ui/table.rb', line 109

def each(&block) = @cells.each(&block)

#empty?Boolean

Returns:

  • (Boolean)


104
# File 'lib/natty-ui/table.rb', line 104

def empty? = @cells.empty?