Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a generally accepted way to add meta information to array-elements indicating how to handle them?
    primarykey
    data
    text
    <p>I am using an array which contains the results of a database-query, which is later formatted as html (for a webapplication) or as csv (for import in a spreadsheet). I want to attach information to the array-element which has some additional information about how the data of this element can be used.</p> <p>For instance, array-element-data...</p> <ul> <li>... can be displayed as a link: then I want the link information attached. The code which creates html from the array can use it to create a link.</li> <li>... is a date of the form <code>2009-09-14</code>: then I want to somehow flag it as being a date. If the usage is for a html-page, it can then be displayed somewhat more beautiful, e.g. <em>Mo Sep 14</em> or <em>Today</em>; if the recipient is a csv it would be best to leave it.</li> </ul> <p>Is there a best-practice way of solving this problem? </p> <p>I did think of several possible solutions, but wanted to ask if someone already knows a "best practice". From possibly best to worst:</p> <ol> <li>Store each array-element as custom-created object (Date,Linkable,Text...), instead of having the array-element as text. Possibly provide a default <code>.to_string()</code> method. </li> <li>Make each array-element a hash, so that I could say <code>a[5][7]['text']</code> or <code>a[5][7]['link']</code>.</li> <li>Make different versions of the array, e.g. <code>textArray[5][7]</code>, <code>linkArray[5][7]</code></li> </ol> <p>Creating the html as a start and just using the text-version seems like a bad idea, as the appearance differs depending on the usage (e.g. <em>2009-09-14</em> vs <em>Mo Sep 14</em>).</p> <p>Or am I just asking the wrong question?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload