Class: JsonFields::ConfigurationParser

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

Class Method Summary collapse

Class Method Details

.parse!(data, options = {}) ⇒ Object

returns a Structure class based on the parsed data



5
6
7
8
9
10
11
# File 'lib/json_fields/configuration_parser.rb', line 5

def self.parse!(data, options = {})
  data.match(/(\A[A-Z][A-Za-z]+)\((\w+)\)/)
  raise JsonFields::ConfigurationError.new("Configuration data is incorrect: #{data}") if $1.nil? || $2.nil?
  klass = "JsonFields::#{$1}#{$2}Structure".safe_constantize
  raise JsonFields::ConfigurationError.new("No Structure found") if klass.nil?
  klass.new(options)
end