Class: CoreData::DataModel

Inherits:
Object
  • Object
show all
Defined in:
lib/core_data/data_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xcdatamodel) ⇒ DataModel

Returns a new instance of DataModel.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/core_data/data_model.rb', line 5

def initialize(xcdatamodel)
  loop do
    case xcdatamodel
    when File, /^\<\?xml/
      xcdatamodel = ::Nokogiri::XML(xcdatamodel) and redo
    when String
      xcdatamodel = ::File.read(xcdatamodel) and redo
    when ::Nokogiri::XML::Document
      break
    else
      raise ArgumentError
    end
  end

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

Instance Attribute Details

#entitiesObject (readonly)

Returns the value of attribute entities.



3
4
5
# File 'lib/core_data/data_model.rb', line 3

def entities
  @entities
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/core_data/data_model.rb', line 3

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/core_data/data_model.rb', line 3

def version
  @version
end