Class: Majesticseo::DataTable

Inherits:
Object
  • Object
show all
Defined in:
lib/majesticseo/data_table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/majesticseo/data_table.rb', line 3

def name
  @name
end

#rowsObject

Returns the value of attribute rows.



3
4
5
# File 'lib/majesticseo/data_table.rb', line 3

def rows
  @rows
end

#rows_countObject

Returns the value of attribute rows_count.



3
4
5
# File 'lib/majesticseo/data_table.rb', line 3

def rows_count
  @rows_count
end

Class Method Details

.create_from_xml(xml) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/majesticseo/data_table.rb', line 5

def self.create_from_xml xml
  table = DataTable.new
  table.headers = xml.attr("Headers")
  table.name = xml.attr("Name")
  table.rows_count = xml.attr("RowsCount").to_i
  table.rows = xml.search("Row").map do |r|
    row = Row.new
    data = r.content.scan(/(?=<!\|)\|(?=!\|)/)
    table.headers.each_index { |i| row.send("#{table.headers[i].underscore}=",data[i])} 
    row
  end
  table
end

Instance Method Details

#headersObject



27
28
29
# File 'lib/majesticseo/data_table.rb', line 27

def headers
  @headers ? @headers : []
end

#headers=(headers) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/majesticseo/data_table.rb', line 19

def headers= headers
  if headers.is_a? String
    @headers = headers.split("|")
  else
    @headers = headers
  end
end