Module: Labrat
- Defined in:
- lib/labrat.rb,
lib/labrat/label.rb,
lib/labrat/config.rb,
lib/labrat/errors.rb,
lib/labrat/options.rb,
lib/labrat/version.rb,
lib/labrat/label_db.rb,
lib/labrat/arg_parser.rb,
lib/labrat/read_files.rb
Overview
A thin wrapper around FatConfig.
Defined Under Namespace
Modules: Config, LabelDb Classes: ArgParser, DimensionError, EmptyLabelError, Label, LabelNameError, OptionError, Options, RecursionError
Constant Summary collapse
- VERSION =
"1.6.0"
Class Method Summary collapse
Class Method Details
.read_label_texts(fname, nl_sep) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/labrat/read_files.rb', line 4 def self.read_label_texts(fname, nl_sep) file = if fname ofname = fname fname = File.(fname) unless File.readable?(fname) raise "Cannot open label file '#{ofname}' for reading" end File.open(fname) else $stdin end texts = [] label = nil file.each do |line| next if /\A\s*#/.match?(line) if /\A\s*\z/.match?(line) # At blank line record any accumulated label into texts, but remove # the nl_sep from the end. if label texts << label.sub(/#{Regexp.quote(nl_sep)}\z/, '') label = nil end else # Append a non-blank line to the current label, creating it if # necessary. label ||= +'' label << line.chomp + nl_sep end end # Last label in the file. texts << label.sub(/#{Regexp.quote(nl_sep)}\z/, '') if label texts end |