Organize by Certification with fallback

Support for macOS users
Post Reply
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Organize by Certification with fallback

Post 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]}
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Organize by Certification with fallback

Post 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.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Organize by Certification with fallback

Post by rednoah »

Code: Select all

any{certification}{"No Certification"}
Here's the related docs: viewtopic.php?f=5&t=1895
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Organize by Certification with fallback

Post 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
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Organize by Certification with fallback

Post 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. :lol:

:idea: 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.
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Organize by Certification with fallback

Post 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.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Organize by Certification with fallback

Post 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...)
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Organize by Certification with fallback

Post by cheaters »

Thanks rednoah! lots of useful information.
Post Reply