webxoss-client/DeckEditor/Searcher.js

35 lines
676 B
JavaScript
Raw Normal View History

2016-10-23 07:28:51 +02:00
'use strict';
function Searcher () {
this.rules = [
ColorRule,
CrossRule,
TypeRule,
RarityRule,
SkillRule,
NoBurstRule,
// LifeBurstRule,
TimmingRule,
LimitingRule,
ClassRule,
PowerRule,
LevelRule,
LimitRule,
NumberRule,
IllustRule,
WxidRule,
NameRule
];
}
Searcher.prototype.search = function (str) {
// if (!str) return [];
var words = str.toLowerCase().split(/\s+/);
var filters = this.rules.map(function (rule) {
return rule.parse(words);
},this);
2017-05-07 10:51:30 +02:00
var infos = Object.keys(CardInfo).map(function (pid) {
return CardInfo[pid];
});
2016-10-23 07:28:51 +02:00
return filters.reduce(function (results,filter) {
return results.filter(filter);
2017-05-07 10:51:30 +02:00
},infos);
2016-10-23 07:28:51 +02:00
};