Class: StHtmlTable::Row
- Inherits:
-
Object
- Object
- StHtmlTable::Row
- Defined in:
- lib/st_html_table/row.rb
Instance Method Summary collapse
-
#add(col_id, text, align: :left, bold: false, italic: false) ⇒ StHtmlTable::Cell
Метод добавляет или изменяет ячейку таблицы, устанавливая ее соедержание, выравнивание, стиль оформления.
- #add_header(header) ⇒ Object
- #get_cell(col_id) ⇒ Object
- #id ⇒ Object
- #id=(id) ⇒ Object
-
#init_row ⇒ Object
:nodoc:.
-
#initialize(table) ⇒ Row
constructor
:nodoc:.
- #row_keys ⇒ Object
- #to_html ⇒ Object
-
#type=(value) ⇒ None
Метод позволяет установить для строки таблицы один из следующих стилей: [:neutral, :fail, :success, :warn].
Constructor Details
#initialize(table) ⇒ Row
:nodoc:
4 5 6 7 8 9 10 11 |
# File 'lib/st_html_table/row.rb', line 4 def initialize(table) # :nodoc: @table = table @cells = Hash.new @id = :none @type = :neutral @ident = 4 end |
Instance Method Details
#add(col_id, text, align: :left, bold: false, italic: false) ⇒ StHtmlTable::Cell
Метод добавляет или изменяет ячейку таблицы, устанавливая ее соедержание, выравнивание, стиль оформления
32 33 34 |
# File 'lib/st_html_table/row.rb', line 32 def add(col_id, text, align: :left, bold: false, italic: false) add_cell(col_id, text, align, bold, italic) end |
#add_header(header) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/st_html_table/row.rb', line 44 def add_header(header) header.each do |id, name| cell = ::StHtmlTable::Cell.new(@table, self) cell.col_id = id.to_sym cell.row_id = self.id cell.is_header = true cell.text = name cell.align = :center cell.bold = true @cells[id.to_sym] = cell end end |
#get_cell(col_id) ⇒ Object
36 37 38 |
# File 'lib/st_html_table/row.rb', line 36 def get_cell(col_id) @cells[col_id] end |
#id ⇒ Object
72 73 74 |
# File 'lib/st_html_table/row.rb', line 72 def id @id end |
#id=(id) ⇒ Object
68 69 70 |
# File 'lib/st_html_table/row.rb', line 68 def id=(id) @id = id end |
#init_row ⇒ Object
:nodoc:
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/st_html_table/row.rb', line 76 def init_row # :nodoc: keys = @table.row_keys keys.each do |id| cell = ::StHtmlTable::Cell.new(@table, self) cell.col_id = id.to_sym cell.row_id = self.id cell.type = @type @cells[id.to_sym] = cell end end |
#row_keys ⇒ Object
40 41 42 |
# File 'lib/st_html_table/row.rb', line 40 def row_keys @cells.keys end |
#to_html ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/st_html_table/row.rb', line 58 def to_html out = Array.new out << (' ' * @ident) + "<tr #{build_color_scheme}>" @cells.each do |id, cell| out << cell.to_html end out << (' ' * @ident) + "</tr>" out.join("\n") end |
#type=(value) ⇒ None
Метод позволяет установить для строки таблицы один из следующих стилей: [:neutral, :fail, :success, :warn]
17 18 19 20 21 22 |
# File 'lib/st_html_table/row.rb', line 17 def type=(value) types = [:neutral, :fail, :success, :warn] raise "Ошибка: тип строки должен быть одним из: #{types.inspect}" unless types.include?(value.to_sym) @type = value.to_sym @cells.each { |id, cell| cell.type = @type } end |