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)



159
160
161
162
163
164
# File 'lib/natty-ui/table.rb', line 159

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.



141
142
143
144
# File 'lib/natty-ui/table.rb', line 141

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

#[](index) ⇒ Cell?



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

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

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



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

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.



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

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

#assign(**attributes) ⇒ Object



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

def assign(**attributes)
  return self if attributes.empty?
  @cells.each { _1.attributes.merge!(**attributes) }
  self
end

#countInteger



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

def count = @cells.size

#delete(cell) ⇒ Object



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

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

#each(&block) ⇒ Object



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

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

#empty?Boolean



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

def empty? = @cells.empty?