Sha256: 4f8d57ca6928f360c7ab873a978ceed51930d3a918622d817a2fc904f0e07d96

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

class CDM::Attribute
  attr_reader :type,
              :name,
              :syncable,
              :optional,
              :defaultValueString

  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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
core_data_motion-0.0.1 lib/core_data_motion/attribute.rb