lib/rbbt/util/tsv/accessor.rb in rbbt-util-2.1.0 vs lib/rbbt/util/tsv/accessor.rb in rbbt-util-3.0.2
- old
+ new
@@ -1,5 +1,6 @@
+require 'rbbt/util/resource'
require 'rbbt/util/misc'
class TSV
## Make sure we overwrite the methods declared by attr_accessor
MAIN_ACCESSORS = :data, :key_field, :fields, :cast
@@ -66,16 +67,16 @@
when (identifiers and Array === identifiers)
case
when (TSV === identifiers.first or identifiers.empty?)
identifiers
when
- identifiers.collect{|f| Path.path(f, datadir, namespace)}
+ identifiers.collect{|f| Resource::Path.path(f, nil, namespace)}
end
when (identifiers and not Array === identifiers)
- [Path.path(identifiers, datadir)]
+ [Resource::Path.path(identifiers, nil, namespace)]
when filename
- Path.path(filename, datadir).identifier_files
+ Resource::Path.path(filename, nil, namespace).identifier_files
else
[]
end
end
@@ -174,11 +175,14 @@
def follow(value)
return nil if value.nil?
if String === value && value =~ /__Ref:(.*)/
return self[$1]
else
- value = NamedArray.name value, fields if Array === value and fields
+
+ if Array === value and fields
+ value = NamedArray.name value, fields
+ end
value
end
end
def [](key)
@@ -243,16 +247,21 @@
"\t" << values * "\t" << "\n"
end
end
def include?(key)
- data.include? key
+ @data.include? key
end
- def to_s(keys = nil)
+ def to_s(keys = nil, no_options = false)
+ if FalseClass === keys or TrueClass === keys
+ no_options = keys
+ keys = nil
+ end
+
str = ""
- str << "#: " << Misc.hash2string(EXTRA_ACCESSORS.collect{|key| [key, self.send(key)]}) << "\n"
+ str << "#: " << Misc.hash2string(EXTRA_ACCESSORS.collect{|key| [key, self.send(key)]}) << "\n" unless no_options
if fields
str << "#" << key_field << "\t" << fields * "\t" << "\n"
end
if keys.nil?