Sha256: aac9ba360250ef11944d9f5b0e01153e30b2b18acda602e7868b4bb55cdbc561

Contents?: true

Size: 987 Bytes

Versions: 2

Compression:

Stored size: 987 Bytes

Contents

require 'nokogiri'

module CoreDataParser
  class DataModel
    attr_reader :name, :version, :entities

    def initialize(data_model)
      loop do
        case data_model
        when File, /^\<\?xml/
          data_model = ::Nokogiri::XML(data_model) and redo
        when String
          case data_model
          when /\.xcdatamodeld?$/
            data_model = Dir[File.join(data_model, "/**/contents")].first and redo
          else
            data_model = ::File.read(data_model) and redo
          end
        when ::Nokogiri::XML::Document
          break
        else
          raise ArgumentError
        end
      end

      model = data_model.at_xpath('model')
      @name = model['name']
      @version = model['systemVersion']
      @entities = model.xpath('entity').collect{|element| Entity.new(element)}
    end
  end
end

require 'core-data-parser/data_model/entity'
require 'core-data-parser/data_model/attribute'
require 'core-data-parser/data_model/relationship'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
core-data-parser-0.1.2 lib/core-data-parser/data_model.rb
core-data-parser-0.1.1 lib/core-data-parser/data_model.rb