arraysrubyraspberry-piwidgetdashing

Format Array to feed into Smash Table Widget


I am creating a Smashing Dashboard that is required to feed information from an xlsx file into a table on the dashboard. This system is running on a Raspberry Pi.

I am able to read from the spreadsheet using the roo gem, this works fine. However the table widget only accepts data in the form

[
    {:cols=>[
        {:class=>"left", :value=>"Office", :style=>"color: #FFFFFF"}, 
        {:class=>"left", :value=>"Aberdeen"}, 
        {:class=>"left", :value=>"Australia"}, 
        {:class=>"left", :value=>"Eurocentral"}, 

        ]
    }, 
    {:cols=>[{:class=>"left", :value=>"Number", :style=>"color: #FFFFFF"}, 
        {:value=>"1234"}, 
        {:value=>"5454"}, 
        {:value=>"9999"}
        ]
    }
]

I am uncertain on how to go about forming an array in this format. I have attempted to loop through the cells in a column and put these into an array then to push these column arrays into a rows array. Below is the code I've written which is far off.

i = 0
    maxRows = is.last_row
    maxCols = is.last_column

    rows = [] 

    #Loop from the first row to the last
    loop do


        #Break out of the loop if we're done
        if (i > maxRows)
            break
        end


         #Put the row into the array as a new row

        j = 0
        cols = [] 
        loop do
            cols[j] = "{:value=> #{is.cell(i,j)}}"
            j +=1 

            if (j > maxRows)
                break
            end



        end

        #rows.push(cols)



    end

I'd appreciate any help on the matter. Resources I need to read, procedures I'm clearly unaware of or anything like this.


Solution

  • It was quite a pain to get this working but I eventually got there.

    Just incase anyone comes across this via google.

    The desired format is an Array containing a new hash at each index, with each hash having a cols key which contains an array where each index is a column in the table. These are further contained within a hash which includes the various keys that are used to render the table.