Class: CoreDataMotion::Attribute
- Inherits:
-
Object
- Object
- CoreDataMotion::Attribute
- Defined in:
- lib/core_data_motion/attribute.rb
Instance Attribute Summary collapse
-
#defaultValueString ⇒ Object
readonly
Returns the value of attribute defaultValueString.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#syncable ⇒ Object
readonly
Returns the value of attribute syncable.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type_key, name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #to_xml ⇒ Object
- #xml_attributes ⇒ Object
- #xml_attributes_as_string ⇒ Object
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, = {}) defaults = CDM::DEFAULT_ATTRIBUTE_OPTIONS type_defaults = CDM::DATA_TYPES[type_key][:default_options] = defaults.merge type_defaults.merge @type = CDM::DATA_TYPES[type_key][:descriptor].to_s @name = name.to_s @syncable = [:syncable] @optional = [:optional] @defaultValueString = [:defaultValueString] end |
Instance Attribute Details
#defaultValueString ⇒ Object (readonly)
Returns the value of attribute defaultValueString.
2 3 4 |
# File 'lib/core_data_motion/attribute.rb', line 2 def defaultValueString @defaultValueString end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/core_data_motion/attribute.rb', line 2 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
2 3 4 |
# File 'lib/core_data_motion/attribute.rb', line 2 def optional @optional end |
#syncable ⇒ Object (readonly)
Returns the value of attribute syncable.
2 3 4 |
# File 'lib/core_data_motion/attribute.rb', line 2 def syncable @syncable end |
#type ⇒ Object (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_xml ⇒ Object
35 36 37 |
# File 'lib/core_data_motion/attribute.rb', line 35 def to_xml " <attribute #{xml_attributes_as_string}/>" end |
#xml_attributes ⇒ Object
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_string ⇒ Object
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 |