Class: StHtmlTable::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/st_html_table/row.rb

Instance Method Summary collapse

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

Метод добавляет или изменяет ячейку таблицы, устанавливая ее соедержание, выравнивание, стиль оформления

Parameters:

  • col_id (Object)

    идентифкатор столбца таблицы

  • text (Object)

    содержание ячейки

  • align (Object) (defaults to: :left)

    выравнивание [:left, :center, :right]

  • bold (Object) (defaults to: false)

    жирное начертание

  • italic (Object) (defaults to: false)

    наклонное начертание

Returns:



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

#idObject



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_rowObject

: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_keysObject



40
41
42
# File 'lib/st_html_table/row.rb', line 40

def row_keys
  @cells.keys
end

#to_htmlObject



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]

Parameters:

  • value (Sym)

    тип строки. При изменении типа строки, все ячейи строки таблицы получат эти же значения

Returns:

  • (None)

    нет



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