![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Template: Matching an entire list
I want one of the clauses of a gpm template to return true iif the only available format is epub. I tested with this:
Code:
program: f = $formats; if list_contains(f, ',', '^epub$', '1', '') then 'foobar' fi What should I do? EDIT: Also, there are other times I might want to match the entire list contents. I am not sure how to do that though. Last edited by ownedbycats; 04-11-2021 at 12:32 AM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
My first thought is to count the items in the list:
Code:
program: f = $formats; if (count(f, ',') == 1) && (list_contains(f, ',', '^epub$', '1', '') ) then 'foobar' fi Code:
program: f = $formats; if contains(f, '^epub$', '1', '') then 'foobar' fi |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,195
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
If you want to extend it so that it is able to test multiple formats also:
Code:
program: mandatory_formats = 'epub,mobi'; if list_equals($formats, ',', mandatory_formats, ',', 1, '') then 'foobar' fi |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This template solves the original problem, to test if a book has epub as its only format:
Code:
program: if $formats == 'epub' then 'foobar' fi |
![]() |
![]() |
![]() |
#5 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks. I will save these
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Related to this: I am trying to remove "Crossover" from fanfics that technically aren't crossovers:
Code:
program: f = $#fanficcat; if contains( f, '^Crossover, Mass Effect Trilogy, Mass Effect: Andromeda$', '1', '' ) then 'Mass Effect Trilogy, Mass Effect: Andromeda' elif contains( f, '^Crossover, Half-Life, Portal$', '1', '' ) then 'Half-Life, Portal' else $#fanficcat; fi Last edited by ownedbycats; 05-04-2021 at 05:51 PM. |
![]() |
![]() |
![]() |
#7 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
EDIT: writing down the rules can help with formulating the correct expressions. If you run into situations where the answer is "It depends" then you aren't done. |
|
![]() |
![]() |
![]() |
#8 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
The blanking out issue I fixed; it was a template error that I fixed in the post before testing in the chain itself.
If the only three items on the list are Crossover, Mass Effect Trilogy, Mass Effect: Andromeda then I want to remove Crossover. If it's Crossover, foobar, Mass Effect Trilogy, Mass Effect: Andromeda then leave Crossover in. |
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: f = $#fanficcat; if list_count(f, ',') ==# 3 && '^Crossover$' inlist f && '^Mass Effect Trilogy$' inlist f && '^Mass Effect: Andromeda$' inlist f then f = 'Mass Effect Trilogy, Mass Effect: Andromeda' fi; f |
|
![]() |
![]() |
![]() |
#10 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
it is pretty specific... the other alternative I thought of is that if I could sort the list before, it would definitely match Crossover, Mass Effect Trilogy, Mass Effect: Andromeda and I could use my original template. Or just checking all nine variations...
|
![]() |
![]() |
![]() |
#11 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Last edited by chaley; 05-04-2021 at 06:42 PM. |
|
![]() |
![]() |
![]() |
#12 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Code:
program: f = list_sort($#fanficcat,0,','); if contains( f, '^Crossover, Mass Effect Trilogy, Mass Effect: Andromeda$', '1', '' ) then 'Mass Effect Trilogy, Mass Effect: Andromeda' elif contains( f, '^Crossover, Half-Life, Portal$', '1', '' ) then 'Half-Life, Portal' else $#fanficcat; fi |
![]() |
![]() |
![]() |
#13 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Remove the semicolon on line 16
Code:
$#fanficcat; The exception is a semicolon at the end of the program. That is accepted because a) it can be detected and b) so many people put one there that I got tired of the questions. |
![]() |
![]() |
![]() |
#14 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,926
Karma: 74801041
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I'm not even sure how that semicolon got there.
![]() |
![]() |
![]() |
![]() |
#15 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
This isn't intended to be criticism ...
When I was first studying computing back in 1971 we had to submit "card decks", a pile of punched computer cards, to run. If *anything* was wrong it cost us hours, so we learned to carefully check the cards for spelling, logic, and syntactic errors before submitting them. Once submitted we would go to the local all-night pizza or donut shop to wait, only to come back to see the error message "You have too many errors. You must be stoned" (yes, this was a real message) and to do it all again. Today the time penalty for not checking for errors is near zero, so people don't bother. The process is "hack at it until it seems to work." The downside: people have less understanding of the basic details. On the other hand, today people are using very complex "APIs" (Application Programming Interfaces) that do an incredible amount of work for you. Problem: these APIs aren't sufficiently documented so the only way to determine what they do is to try using them, over and over until one is confident that the behavior is understood. But of course the behavior isn't understood because the edge conditions aren't tested. Sigh... |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom list template | Laval | Related Tools | 6 | 10-11-2022 09:13 AM |
Template: Converting a search & replace into a template | ownedbycats | Library Management | 11 | 03-26-2021 04:32 AM |
Template: Strcat matching | ownedbycats | Library Management | 7 | 03-20-2021 10:15 PM |
Create a template to only list one author. | PMGeuze | Calibre | 2 | 12-04-2013 02:53 PM |