Page 1 of 1
Organize by Certification with fallback
Posted: 02 Apr 2017, 08:43
by cheaters
I am trying to organize by certification with a fall back to a folder titled "unrated" if there is no certification. I have tried for hours,,, searched and just can't figure it out. This doesn't work, just leaves the certification out completely.
Code: Select all
Volumes/Movies/{certification ?: "unrated"}/{ny} {[certification]} {[runtime + ' min']} {genres.take(4) ?: null} {[imdbid, rating]}
Re: Organize by Certification with fallback
Posted: 02 Apr 2017, 16:55
by cheaters
I found this forum
viewtopic.php?f=6&t=1194&p=7210&hilit=i ... mpty#p7210 which has some clues but doesn't really apply since I am not needing one of two options but needing to substitute my own text if an empty value is returned.
if not undefined {" $certification"}
else not undefined {imdb.certification}
(and if {imdb.certification} = 13, return PG-13, along with other similar replacements for other stuff-ups that imdb may return)
else ignore?
Code: Select all
{' '+any{imdb.certification}{certification}.replaceAll(/^\d+$/, 'PG-$0')}
Any help would be appreciated. I was up until five in the morning and couldn't get it. Not familiar with the language which makes it nearly impossible to search. I know these are called formula and arguments, other than that I use general terms to search and what I have found is that everything is described in highly technical terms. How would you search for an existing answer for my problem, an example would help.
Re: Organize by Certification with fallback
Posted: 02 Apr 2017, 17:50
by rednoah
Code: Select all
any{certification}{"No Certification"}
Here's the related docs:
viewtopic.php?f=5&t=1895
Re: Organize by Certification with fallback
Posted: 02 Apr 2017, 18:03
by cheaters
THANKS!!!!!
I just found the answer by accident, after looking at page you wrote, and fiddling around with it. Can you explain the function what - and + do in this situation?
I assumed the
any would require more than one argument
viewtopic.php?t=1895
Re: Organize by Certification with fallback
Posted: 02 Apr 2017, 18:19
by rednoah
1.
any(Closure...) does indeed require 2 or more arguments:
Code: Select all
any{certification}{"No Certification"}
is syntactic sugar for:
Code: Select all
any({certification}, {"No Certification"})
where the first argument is a closure that yields the certification and the second argument a closure that yields a constant String value.
2.
jprokos wrote:Can you explain the function what - and + do in this situation?
Which "this situation" are you referring to? I don't remember using +/- in my
any(Closure...) examples.
a + b is the same as
a.plus(b) so depending on the type of a, the plus method of that type does different things.
Re: Organize by Certification with fallback
Posted: 02 Apr 2017, 18:35
by cheaters
Have a beer. I sent a small donation.
Where do I find all of this information. I looked at Groovy code,,,, I had one question and ended up with 30,000 more.
Re: Organize by Certification with fallback
Posted: 02 Apr 2017, 18:59
by rednoah
Unless you already have a good programming background with a bit of Java skills mixed in, understanding how things work internally can get tricky.
Here's all you need to know about Groovy syntax and semantics:
http://docs.groovy-lang.org/latest/html/documentation/
e.g. What does
"A" + "B" do?
String Concatenation
e.g. Why does
any{certification}{"A" + "B"} work the way it does?
Closures
e.g. What happens when
any{x}{y}{z} is called?
syntax sugar and
any(Object...)
Re: Organize by Certification with fallback
Posted: 03 Apr 2017, 07:09
by cheaters
Thanks rednoah! lots of useful information.