Class: PnoteClient::Documents::Hml::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/pnote_client/documents/hml/table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row_count: 0, col_count: 0) ⇒ Table

Returns a new instance of Table.



23
24
25
26
27
# File 'lib/pnote_client/documents/hml/table.rb', line 23

def initialize(row_count: 0, col_count: 0)
  @row_count = row_count
  @col_count = col_count
  @rows = []
end

Instance Attribute Details

#col_countObject (readonly)

Returns the value of attribute col_count.



21
22
23
# File 'lib/pnote_client/documents/hml/table.rb', line 21

def col_count
  @col_count
end

#row_countObject (readonly)

Returns the value of attribute row_count.



21
22
23
# File 'lib/pnote_client/documents/hml/table.rb', line 21

def row_count
  @row_count
end

#rowsObject (readonly)

Returns the value of attribute rows.



21
22
23
# File 'lib/pnote_client/documents/hml/table.rb', line 21

def rows
  @rows
end

Class Method Details

.from_tag(table_tag) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pnote_client/documents/hml/table.rb', line 8

def self.from_tag(table_tag)
  row_count = table_tag['RowCount']
  col_count = table_tag['ColCount']

  table = self.new(row_count: row_count.to_i, col_count: col_count.to_i)
  row_tags = table_tag.xpath("ROW")
  row_tags.each do |row_tag|
    table.add_row(TableRow.from_tag(row_tag))
  end

  return table
end

Instance Method Details

#add_row(row) ⇒ Object



29
30
31
# File 'lib/pnote_client/documents/hml/table.rb', line 29

def add_row(row)
  @rows << row
end

#contentObject



33
34
35
36
37
38
39
40
41
# File 'lib/pnote_client/documents/hml/table.rb', line 33

def content
  json = {
    col_count: @col_count,
    row_count: @row_count,
    rows: rows_content
  }.to_json

  return "\n![table](#{json})\n"
end

#textable?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/pnote_client/documents/hml/table.rb', line 43

def textable?
  return true
end