Class: BLM::Document

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

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Document

Returns a new instance of Document.



3
4
5
# File 'lib/blm.rb', line 3

def initialize(source)
	@source = source
end

Instance Method Details

#dataObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/blm.rb', line 30

def data
	return @data if defined?(@data)

	@data = []
	get_contents(@source, "#DATA#", "#").split(header[:eor]).each do |line|
		entry = {}
		line.split(header[:eof]).each_with_index do |field, index|
			entry[definition[index].to_sym] = field.strip
		end
		@data << Row.new(entry)
	end
	return @data
end

#definitionObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/blm.rb', line 19

def definition
	return @definition if defined?(@definition)

	@definition = []
	get_contents(@source, "#DEFINITION#", "#").split(header[:eor]).first.split(header[:eof]).each do |field|
		next if field.empty?
		@definition << field.downcase.strip
	end
	return @definition
end

#headerObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blm.rb', line 7

def header
	return @header if defined?(@header)

	@header = {}
	get_contents(@source, "#HEADER#", "#").each_line do |line|
		next if line.empty?
		key, value = line.split(" : ")
		@header[key.downcase.to_sym] = value.gsub(/'/, "").strip
	end
	return @header
end