I have a field “A” with custonlist type : title, year, venue, local of publication, language, media, type of publication, pages, ISSN, volume, number
i need new column “B”
if this colum A == year
data generate in new column “B” data about year por example: 2010, 2004, 2005
if this colum A == language
data generate in new column “B” data about"English", “Spanish”, “Portugues”
which is the data type of the new column “B”?
There are several solutions to your problem:
- 1. Upload a new [dataset](https://www.mockaroo.com/lists/new)
-
`set.csv`
```
A,B
year,'[2010, 2004, 2005,...]'
language,'["English", "Spanish", "Portugues",...]'
```
where [...] is a JSON array
then in your schema you could do some voodoo magic to parse the JSON array into a Ruby list and choose a random reference... Sorry I just put myself to sleep for a second.
Don't do that. Not only would it be tedious and time consuming, but it would require you to limit yourself to a finite number of different years random options.
- 2. Use scripting
-
I have spent an inordinate amount of time over the last week testing the limits of Mockaroo's scripting engine. It is actually quite broad, including
- **sequence**
-
- **`while`**
```
i = 0
num = this
this = ""
while i < num do
this += i.to_s + ", "
i +=1
end
this = this
```
- **`until`**
```
this = 0
until random(0, 1) == 0
this += 1
end
this = "there were " + this.to_s + " random 0's"
```
- **`each`**
```
arr = this
this = ""
arr.each do |i|
this += "#{i}..."
end
this = this
```
- etc... (give me a break ruby has a lot of repetition constructs :smile:)
- **selection**
-
- **`if`**
```
if this
this = "it was true"
else
this = "it was false"
end
this = this
```
- **`case`**
```
case this
when 1..5
this = "It's between 1 and 5"
when 6
this = "It's 6"
else
this = "You gave me '" + this.to_s + "' -- I have no idea what to do with that."
end
this = this
```
- **`unless`**
```
unless this.downcase == this
this = "'" + this + "' is an uppercase letter"
else
this = "'" + this + "' is a lower case letter"
end
this = this
```
- **functions**
-
```
def hello()
return "hello"
end
this = hello()
```
- **Data Structures**
-
- [**`Array`**](http://ruby-doc.org/core-2.2.0/Array.html)
```
this = ['one fish', 'two fish', 'red fish', 'blue fish'][this - 1]
```
- [**`Hash`**](http://docs.ruby-lang.org/en/2.0.0/Hash.html)
```
h = {
'L'=>'Large',
'M'=>'Medium',
'S'=>'Small'
}
h.default = '??'
this = h[this]
</li>
</dd>
</dl>
The most notable limitations which i *have* encountered are:
1. Cannot define classes (as far as I can tell)
2. No static variables (a field cannot reference previous records)
3. Can't see which sequential repetition this record is - [my workaround](http://forum.mockaroo.com/t/is-it-possible-to-get-get-the-number-of-times-we-have-iterated-through-a-sequence/338)
4. No access to reflection (really hampered my attempts to peek under the api's metaphorical hood)
Final thoughts
===
You can do an awful lot with this scripting API, it will fight you (a lot) sometimes but at the end of the day is greatest weakness is that sometimes it is actually too random (not an insult).
[**Examples**](https://www.mockaroo.com/ceecfbb0)
Note
===
You likely noticed that I always end my formulas by assigning `this = ...` (sometimes event `this = this`) I don't fully understand why but I have had some bugs occur in the past where formulas were not being evaluated. This seems to solve it. (I have no idea why).