Class: Kafo::DataTypeParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/data_type_parser.rb

Constant Summary collapse

TYPE_DEFINITION =
/^type\s+([^\s=]+)\s*=\s*(.+?)(\s+#.*)?\s*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ DataTypeParser

Returns a new instance of DataTypeParser.



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
# File 'lib/kafo/data_type_parser.rb', line 9

def initialize(manifest)
  @logger = KafoConfigure.logger

  lines = []
  type_line_without_newlines = +''
  manifest.each_line do |line|
    line = line.force_encoding("UTF-8").strip
    next if line.start_with?('#')

    line = line.split(' #').first.strip
    if line =~ TYPE_DEFINITION
      lines << type_line_without_newlines
      type_line_without_newlines = line
    else
      type_line_without_newlines << line
    end
  end
  lines << type_line_without_newlines

  @types = {}
  lines.each do |line|
    if (type = TYPE_DEFINITION.match(line))
      @types[type[1]] = type[2]
    end
  end
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



7
8
9
# File 'lib/kafo/data_type_parser.rb', line 7

def types
  @types
end

Instance Method Details

#registerObject



36
37
38
39
40
41
# File 'lib/kafo/data_type_parser.rb', line 36

def register
  @types.each do |name,target|
    @logger.debug("Registering extended data type #{name}")
    DataType.register_type(name, target)
  end
end