Class: Krane::BindingsParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_string = nil) ⇒ BindingsParser

Returns a new instance of BindingsParser.


12
13
14
# File 'lib/krane/bindings_parser.rb', line 12

def initialize(initial_string = nil)
  @raw_bindings = Array(initial_string)
end

Class Method Details

.parse(string) ⇒ Object


8
9
10
# File 'lib/krane/bindings_parser.rb', line 8

def self.parse(string)
  new(string).parse
end

Instance Method Details

#add(string) ⇒ Object


16
17
18
# File 'lib/krane/bindings_parser.rb', line 16

def add(string)
  @raw_bindings << string
end

#parseObject


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/krane/bindings_parser.rb', line 20

def parse
  result = {}
  @raw_bindings.each do |string|
    bindings = parse_file(string) || parse_json(string) || parse_csv(string)
    unless bindings
      raise ArgumentError, "Failed to parse bindings."
    end
    result.deep_merge!(bindings)
  end
  result
end