class CoreData::DataModel::Attribute
Attributes
default_value[R]
identifier[R]
maximum_value[R]
minimum_value[R]
name[R]
regular_expression[R]
type[R]
version_hash_modifier[R]
Public Class Methods
new(attribute)
click to toggle source
# File lib/core_data/data_model/attribute.rb, line 8 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 = default_value_from_string(attribute['defaultValueString']) @minimum_value = range_value_from_string(attribute['minValueString']) @maximum_value = range_value_from_string(attribute['maxValueString']) @regular_expression = begin Regexp.new(attributes['regularExpressionString']) rescue StandardError nil end @optional = attribute['optional'] == 'YES' @transient = attribute['transient'] == 'YES' @indexed = attribute['indexed'] == 'YES' @syncable = attribute['syncable'] == 'YES' end
Public Instance Methods
to_s()
click to toggle source
# File lib/core_data/data_model/attribute.rb, line 32 def to_s [@name, @type].to_s end
Private Instance Methods
default_value_from_string(string)
click to toggle source
# File lib/core_data/data_model/attribute.rb, line 42 def default_value_from_string(string) return nil unless string case @type when 'Integer 16', 'Integer 32', 'Integer 64' string.to_i when 'Float', 'Decimal' string.to_f when 'Boolean' string == 'YES' else string end end
range_value_from_string(string)
click to toggle source
# File lib/core_data/data_model/attribute.rb, line 57 def range_value_from_string(string) return nil unless string case @type when 'Float', 'Decimal' string.to_f when 'Date' string else string.to_i end end