lib/rbbt/tsv/manipulate.rb in rbbt-util-5.2.4 vs lib/rbbt/tsv/manipulate.rb in rbbt-util-5.3.0
- old
+ new
@@ -343,10 +343,12 @@
through do |key, value|
new[key] = value if yield(value)
end
else
pos = identify_field method
+ raise "Field #{ method } not identified. Available: #{ fields * ", " }" if pos.nil?
+
through do |key, values|
new[key] = values if yield(values[pos])
end
end
end
@@ -449,15 +451,36 @@
nv = nv.send(cast) unless cast.nil?
new[k] = nv
end
end
- new.type = :single
+ case type
+ when :double, :flat
+ new.type = :flat
+ else
+ new.type = :single
+ end
new
end
+ def process_key(&block)
+ new = annotate({})
+ through do |key, values|
+ key = case
+ when block.arity == 1
+ yield(key)
+ when block.arity == 2
+ yield(key, values)
+ else
+ raise "Unexpected arity in block, must be 1, 2 or 3: #{block.arity}"
+ end
+ new[key] = values
+ end
+ new
+ end
+
def process(field, &block)
field_pos = identify_field field
through do |key, values|
next if values.nil?
@@ -496,9 +519,10 @@
values[field_pos] = new_values
end
self[key] = values
end
end
+
self
end
def add_field(name = nil)
old_monitor = @monitor