lib/rbbt/tsv/change_id.rb in rbbt-util-5.8.0 vs lib/rbbt/tsv/change_id.rb in rbbt-util-5.8.1

- old
+ new

@@ -1,9 +1,9 @@ require 'rbbt/tsv' module TSV - def self.change_key(tsv, format, options = {}) + def self.change_key(tsv, format, options = {}, &block) options = Misc.add_defaults options, :persist => false, :identifiers => tsv.identifiers identifiers, persist_input = Misc.process_options options, :identifiers, :persist_input if not tsv.fields.include? format @@ -19,22 +19,24 @@ end tsv = tsv.reorder(format, tsv.fields - [format]) tsv = tsv.to_flat if orig_type == :flat + tsv = tsv.to_list(&block) if orig_type == :list + tsv else tsv.reorder(format) end end - def change_key(format, options = {}) + def change_key(format, options = {}, &block) options = Misc.add_defaults options, :identifiers => self.identifiers - TSV.change_key(self, format, options) + TSV.change_key(self, format, options, &block) end - def self.swap_id(tsv, field, format, options = {}) + def self.swap_id(tsv, field, format, options = {}, &block) options = Misc.add_defaults options, :persist => false, :identifiers => tsv.identifiers identifiers, persist_input = Misc.process_options options, :identifiers, :persist fields = identifiers.all_fields.include?(field)? [field] : nil @@ -59,9 +61,11 @@ tsv.fields = tsv.fields.collect{|f| f == field ? format : f} end tsv = tsv.to_flat if orig_type == :flat + + tsv = tsv.to_list(&block) if orig_type == :list tsv end def swap_id(*args)