diff --git a/python/citation_vim/builder.py b/python/citation_vim/builder.py index 8a6b09a..2dec015 100644 --- a/python/citation_vim/builder.py +++ b/python/citation_vim/builder.py @@ -33,7 +33,7 @@ def get_sub_source(self): output = [] for item in self.get_items(): if self.context['collection'] == "" or self.context['collection'] in item.collections: - output.append(self.item_to_array(item)) + output.append(item.to_list(self.context)) return output def get_collections(self): @@ -66,30 +66,20 @@ def filter_duplicate_keys(self): output = [] for item in items: if last_item.key == item.key: - output.append(self.item_to_array(item)) + output.append(item.to_list(self.context)) last_item = item return output - def item_to_array(self, item): - return [ - getattr(item, self.context['source_field']), - item.describe(self.context), - item.file, - item.combined, - ] - def get_items(self): """ - Returns items from cache or parser + Returns items from cache or parser """ - if self.cache and self.is_cached(): + if self.cache and self.is_cached(): return self.read_cache() parser = self.get_parser() + items = parser.load() if self.context['reverse_order']: - items = parser.load() items.reverse() - else: - items = parser.load() if self.cache: self.write_cache(items) return items diff --git a/python/citation_vim/item.py b/python/citation_vim/item.py index 094dc57..83910f8 100644 --- a/python/citation_vim/item.py +++ b/python/citation_vim/item.py @@ -75,3 +75,11 @@ def get_field_value(self, field): def wrap(self, string): wrapper = self.context['wrap_chars'] return u'%s%s%s' % (wrapper[0], string, wrapper[1]) + + def to_list(self, context): + return [ + getattr(self, self.context['source_field']), + self.describe(self.context), + self.file, + self.combined, + ]