1 # Copyright (C) 2007-2011 Martin A. Hansen.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # http://www.gnu.org/copyleft/gpl.html
19 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
21 # This software is part of the Biopieces framework (www.biopieces.org).
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 require 'maasha/filesys'
27 # Error class for all exceptions to do with Boulder.
28 class BoulderError < StandardError; end
33 # Class to manipulate boulder records - Lincoln Steins own
35 # http://stein.cshl.org/boulder/docs/Boulder.html
36 class Boulder < Filesys
37 # Initialize a Boulder object.
38 # Options are for testing purposes only.
39 def initialize(input=STDIN, output=STDOUT)
45 while not @input.eof? do
46 block = @input.gets(SEP)
47 raise BoulderError, "Missing record seperator" unless block =~ /#{SEP}$/
51 block.chomp(SEP).each_line do |line|
52 key, val = line.chomp.split('=', 2)
54 raise BoulderError, "Missing key/value seperator" if val.nil?
55 raise BoulderError, "Missing key" if key.empty?
56 raise BoulderError, "Missing value" if val.empty?
58 record[key.to_sym] = val
65 # Method that converts and returns a hash record as
67 def to_boulder(record)
70 record.each_pair do |key, val|
71 str << "#{key}=#{val}\n"