Sha256: c4edb47bd91afe8faf5922c9770ee48b747e72081b04b1155bc06ead26f169b8

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

class Rack::CoreData::DataModel
  class Attribute
    attr_reader :name, :type, :identifier, :version_hash_modifier, :default_value

    def initialize(attribute)
      raise ArgumentError unless ::Nokogiri::XML::Element === attribute

      @name = attribute['name']
      @type = attribute['attributeType']
      @identifier = attribute['elementID']
      @version_hash_modifier = attribute['versionHashModifier']
      @default_value = case @type
                       when "Integer 16", "Integer 32", "Integer 64"
                         attribute['defaultValueString'].to_i
                       when "Float", "Decimal"
                         attribute['defaultValueString'].to_f
                       end if attribute['defaultValueString']

      @optional = attribute['optional'] == "YES"
      @transient = attribute['transient'] == "YES"
      @indexed = attribute['indexed'] == "YES"
      @syncable = attribute['syncable'] == "YES"
    end

    def to_s
      @name
    end

    [:optional, :transient, :indexed, :syncable].each do |symbol|
      define_method("#{symbol}?") {!!instance_variable_get(("@#{symbol}").intern)}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-core-data-0.0.3 ./lib/rack/core-data/data_model/attribute.rb
rack-core-data-0.0.2 ./lib/rack/core-data/data_model/attribute.rb
rack-core-data-0.0.1 ./lib/rack/core-data/data_model/attribute.rb