Sha256: d41c948ab65312ca67de46a5a63073459c8082cd993c1f717d123c6347ad4b4e

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require 'eeml/csv_parser_v1'
require 'eeml/csv_parser_v2'
require 'eeml/libxml_eeml_parser_v005'
require 'eeml/libxml_eeml_parser_v051'
require 'eeml/json_environment_parser_v005'
require 'eeml/json_environment_parser_v006'
require 'eeml/json_environment_parser_v100'

module Eeml
  class EnvironmentBuilder # :nodoc:

    include LibXML

    def self.build_from_xml(xml_str)
      begin
        xml = XML::Parser.string(xml_str).parse
        if xml.root.namespaces.default.to_s == Constants::EEML['0.5.1'][:href]
          parser = LibXMLEemlParserV051.new 
        else
          parser = LibXMLEemlParserV005.new
        end
      rescue => e
        parser = LibXMLEemlParserV005.new
      end
      return parser.make_environment_from_xml(xml_str)
    end

    def self.build_list_from_xml(xml_str)
      parser = LibXMLEemlParserV005.new
      return parser.make_environments_from_xml(xml_str)
    end

    def self.build_from_json(json_str)
      json = JSON.parse(json_str)
      if json["version"].to_i == Constants::EEML['0.5.0'][:version].to_i
        parser = JsonEnvironmentParserV005.new
      elsif json["version"] == Constants::JSON_API['1.0.0'][:version]
	parser = JsonEnvironmentParserV100.new
      elsif json["version"].to_f == Constants::JSON_API['0.6-alpha'][:version].to_f
        parser = JsonEnvironmentParserV006.new
      else
        raise JSON::ParserError, "Invalid version specification. Permitted versions are #{Constants::EEML['0.5.0'][:version]}, #{Constants::JSON_API["0.6-alpha"][:version]} and #{Constants::JSON_API["1.0.0"][:version]}"
      end
      return parser.make_environment_from_hash(json)
    end

    def self.build_from_csv(csv_str, version = :v1)
      if version == :v2
        parser = CsvParserV2
      else
        parser = CsvParserV1
      end
      parser.make_environment_from_csv(csv_str)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eeml-0.0.25 lib/eeml/environment_builder.rb
eeml-0.0.24 lib/eeml/environment_builder.rb