Class: CTioga2::Data::Backends::TextBackend

Inherits:
Backend
  • Object
show all
Includes:
Dobjects
Defined in:
lib/ctioga2/data/backends/backends/text.rb

Constant Summary collapse

UNCOMPRESSORS =

A constant holding a relation extension -> command to decompress (to be fed to sprintf with the filename as argument)

{
  ".gz" => "gunzip -c %s",
  ".bz2" => "bunzip2 -c %s",
  ".lzma" => "unlzma -c %s",
  ".lz" => "unlzma -c %s",
  ".xz" => "unxz -c %s",
}

Instance Method Summary collapse

Methods inherited from Backend

#dataset, describe, #description, #has_set?, list_backends, #set_param_from_string, #sets_available

Methods included from BackendDescriptionExtend

#base_description, #create_factory, #describe, #description, #factory_class, #factory_description, #factory_description_hash, #factory_description_list, #has_factory?, #inherit_parameters, #param, #param_accessor, #param_reader, #param_writer, #register_class, #set_description

Methods included from Log

debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn

Constructor Details

#initializeTextBackend

Returns a new instance of TextBackend.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ctioga2/data/backends/backends/text.rb', line 89

def initialize
  @dummy = nil
  @current = nil   
  # Current is the name of the last file used. Necessary for '' specs.
  @current_data = nil       # The data of the last file used.
  @skip = 0
  @included_modules = [NaN]    # to make sure we give them to
  # Dvector.compute_formula
  @default_column_spec = "1:2"

  @separator = /\s+/

  # We don't split data by default.
  @split = false

  @param_regex = nil

  @header_line_regex = /^\#\#\s*/

  super()

  # Override Backend's cache - for now.
  @cache = {}               # A cache file_name -> data

  @param_cache = {}     # Same thing as cache, but for parameters

  @headers_cache = {}   # Same thing as cache, but for header
                        # lines.

end

Instance Method Details

#expand_sets(spec) ⇒ Object

Expands specifications into few sets. This function will separate the set into a file spec and a col spec. Within the col spec, the 2##6 keyword is used to expand to 2,3,4,5,6. 2## followed by a non-digit expands to 2,…,last column in the file. For now, the expansions stops on the first occurence found, and the second form doesn’t work yet. But soon…



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ctioga2/data/backends/backends/text.rb', line 131

def expand_sets(spec)
  if m = /(\d+)##(\D|$)/.match(spec)
    a = m[1].to_i 
    trail = m[2]
    b = read_file(spec)
    b = (b.length - 1) 
    ret = []
    a.upto(b) do |i|
      ret << m.pre_match + i.to_s + trail + m.post_match
    end
    return ret
  else
    return super
  end
end

#extend(mod) ⇒ Object



120
121
122
123
# File 'lib/ctioga2/data/backends/backends/text.rb', line 120

def extend(mod)
  super
  @included_modules << mod
end