View Single Post
Old 07-07-2013, 07:39 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
First point: if your library has more than a thousand or so books, you should use the function that PeterT showed you in your original post: approximate_formats. The formats field verifies that the formats are actually on the disk, which can be slow. The approximate_formats function takes the formats from the database but does not verify them. In the vast majority of cases they produce the same answer, but they do not if formats "disappeared" through non-calibre manipulations.

To use approximate_formats you must use Template Program Mode. The template you posted above would become
Code:
{:'contains(approximate_formats(), 'EPUB', 'Yes', '')'}
As for your question in this post, there are several ways to solve it. One will be the set manipulation that PeterT proposes, which I will leave to him.

Another solution uses the fact that the "pattern" argument to the contains function is a regular expression. Regular expressions can contain multiple subpatterns separated by the | character. Using that capability, the following template will display 'Yes' if approximate_formats contains 'EPUB' or 'MOBI'. You can add as many formats as you like.
Code:
{:'contains(approximate_formats(), 'EPUB|MOBI', 'Yes', '')'}
A more brute-force solution would be to use General Program Mode and test for each format explicitly. This would also allow you to customize the display for each format
Code:
program:
	f = approximate_formats();
	first_non_empty(
		contains(f, 'EPUB', 'Got an epub', ''),
		contains(f, 'PRC', 'Oh no, a prc', ''),
		contains(f, 'MOBI', 'Wow -- a mobi!', '')
	)

Last edited by chaley; 07-07-2013 at 09:22 AM. Reason: add link to calibre regexp tutorial
chaley is offline   Reply With Quote