Class: Athena::Parser

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/athena/parser.rb

Overview

#

A component of athena, the database file converter. #

#

Copyright © 2007-2009 University of Cologne, #

Albertus-Magnus-Platz,                              #
50932 Cologne, Germany                              #
                                                    #

Authors: #

Jens Wille <[email protected]>                                    #
                                                                        #

athena is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. #

#

athena is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. #

#

You should have received a copy of the GNU General Public License along # with athena. If not, see <www.gnu.org/licenses/>. #

#

++

Constant Summary collapse

DEFAULT_SEPARATOR =
', '
DEFAULT_EMPTY =
'<<EMPTY>>'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#verbose

Constructor Details

#initialize(config, spec) ⇒ Parser

Returns a new instance of Parser.



39
40
41
42
# File 'lib/athena/parser.rb', line 39

def initialize(config, spec)
  @config = build_config(config)
  @spec   = Athena::Formats[:in, spec].new(self)
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



37
38
39
# File 'lib/athena/parser.rb', line 37

def block
  @block
end

#configObject (readonly)

Returns the value of attribute config.



36
37
38
# File 'lib/athena/parser.rb', line 36

def config
  @config
end

#specObject (readonly)

Returns the value of attribute spec.



36
37
38
# File 'lib/athena/parser.rb', line 36

def spec
  @spec
end

Instance Method Details

#parse(source, &block) ⇒ Object



44
45
46
47
48
49
# File 'lib/athena/parser.rb', line 44

def parse(source, &block)
  self.block = block

  res = spec.parse(source)
  block ? res : Athena::Record.records
end