Class: Baldr::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, params = {}) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
12
13
14
# File 'lib/baldr/parser.rb', line 5

def initialize(input, params = {})
  @params = params
  @input = input

  parse

  if @params[:skip_validation] != true && successful?
    validate
  end
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#root_typeObject (readonly)

Returns the value of attribute root_type.



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

def root_type
  @root_type
end

#separatorsObject (readonly)

Returns the value of attribute separators.



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

def separators
  @separators
end

Instance Method Details

#envelopesObject



20
21
22
23
24
25
26
# File 'lib/baldr/parser.rb', line 20

def envelopes
  if @root_type == :envelope
    @roots
  else
    raise Baldr::Error, "interchange doesn't have envelopes"
  end
end

#successful?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/baldr/parser.rb', line 16

def successful?
  @error.nil?
end

#transactionsObject



28
29
30
31
32
33
34
# File 'lib/baldr/parser.rb', line 28

def transactions
  if @root_type == :transaction
    @roots
  else
    @roots.map(&:transactions).flatten
  end
end

#validateObject



36
37
38
39
40
41
42
43
# File 'lib/baldr/parser.rb', line 36

def validate
  if @roots
    @roots.each { |e| Baldr::Validator.validate!(e, @grammar, @version) }
    @roots.each { |e| Baldr::Types.convert_after_parse!(e, @grammar, @version) }
  end
rescue Baldr::Error => e
  @error = e.message
end