Class: MajesticSeo::Api::DataTable
- Inherits:
-
Object
- Object
- MajesticSeo::Api::DataTable
- Defined in:
- lib/majestic_seo/api/data_table.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#node ⇒ Object
Returns the value of attribute node.
-
#row_count ⇒ Object
Returns the value of attribute row_count.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(node) ⇒ DataTable
constructor
A new instance of DataTable.
- #parse ⇒ Object
- #parse_row(row) ⇒ Object
- #split(text) ⇒ Object
Constructor Details
#initialize(node) ⇒ DataTable
Returns a new instance of DataTable.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/majestic_seo/api/data_table.rb', line 38 def initialize(node) @node = node if (@node) @name = @node["Name"] || nil @row_count = @node["RowsCount"] || 0 @headers = @node["Headers"] || [] @rows = [] parse end end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
36 37 38 |
# File 'lib/majestic_seo/api/data_table.rb', line 36 def headers @headers end |
#name ⇒ Object
Returns the value of attribute name.
36 37 38 |
# File 'lib/majestic_seo/api/data_table.rb', line 36 def name @name end |
#node ⇒ Object
Returns the value of attribute node.
36 37 38 |
# File 'lib/majestic_seo/api/data_table.rb', line 36 def node @node end |
#row_count ⇒ Object
Returns the value of attribute row_count.
36 37 38 |
# File 'lib/majestic_seo/api/data_table.rb', line 36 def row_count @row_count end |
#rows ⇒ Object
Returns the value of attribute rows.
36 37 38 |
# File 'lib/majestic_seo/api/data_table.rb', line 36 def rows @rows end |
Instance Method Details
#parse ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/majestic_seo/api/data_table.rb', line 51 def parse rows = @node.xpath("Row") if (@headers && rows && rows.any?) @headers = split(@headers) rows.each do |row| parse_row(row) end end end |
#parse_row(row) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/majestic_seo/api/data_table.rb', line 63 def parse_row(row) if (row && row.content) row = row.content row_hash = {} splitted_row = split(row) @headers.each_with_index do |header, index| value = splitted_row[index].strip value = (value && value != "") ? value : nil row_hash[header] = value end @rows << row_hash if (row_hash && !row_hash.empty?) end end |
#split(text) ⇒ Object
79 80 81 |
# File 'lib/majestic_seo/api/data_table.rb', line 79 def split(text) splitted = text.split(/\|(?!\|)/) end |