Class: CoreDataMotion::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/core_data_motion/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_key, name, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/core_data_motion/attribute.rb', line 8

def initialize(type_key, name, options = {})
  defaults = CDM::DEFAULT_ATTRIBUTE_OPTIONS
  type_defaults = CDM::DATA_TYPES[type_key][:default_options]
  options = defaults.merge type_defaults.merge options

  @type               = CDM::DATA_TYPES[type_key][:descriptor].to_s
  @name               = name.to_s
  @syncable           = options[:syncable]
  @optional           = options[:optional]
  @defaultValueString = options[:defaultValueString]
end

Instance Attribute Details

#defaultValueStringObject (readonly)

Returns the value of attribute defaultValueString.



2
3
4
# File 'lib/core_data_motion/attribute.rb', line 2

def defaultValueString
  @defaultValueString
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/core_data_motion/attribute.rb', line 2

def name
  @name
end

#optionalObject (readonly)

Returns the value of attribute optional.



2
3
4
# File 'lib/core_data_motion/attribute.rb', line 2

def optional
  @optional
end

#syncableObject (readonly)

Returns the value of attribute syncable.



2
3
4
# File 'lib/core_data_motion/attribute.rb', line 2

def syncable
  @syncable
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/core_data_motion/attribute.rb', line 2

def type
  @type
end

Instance Method Details

#to_xmlObject



35
36
37
# File 'lib/core_data_motion/attribute.rb', line 35

def to_xml
  "    <attribute #{xml_attributes_as_string}/>"
end

#xml_attributesObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/core_data_motion/attribute.rb', line 20

def xml_attributes
  attrs = {
    type:                 type,
    name:                 name,
    syncable:             syncable,
    optional:             optional,
    defaultValueString:   defaultValueString
  }
  attrs.reject { |k, v| v.nil? }
end

#xml_attributes_as_stringObject



31
32
33
# File 'lib/core_data_motion/attribute.rb', line 31

def xml_attributes_as_string
  xml_attributes.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
end