Class: Lafcadio::ClassDefinitionXmlParser::FieldAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/lafcadio/domain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value_class, objectFieldClass = nil) ⇒ FieldAttribute

Returns a new instance of FieldAttribute.



73
74
75
76
# File 'lib/lafcadio/domain.rb', line 73

def initialize( name, value_class, objectFieldClass = nil )
	@name = name; @value_class = value_class
	@objectFieldClass = objectFieldClass
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



71
72
73
# File 'lib/lafcadio/domain.rb', line 71

def name
  @name
end

#value_classObject (readonly)

Returns the value of attribute value_class.



71
72
73
# File 'lib/lafcadio/domain.rb', line 71

def value_class
  @value_class
end

Instance Method Details

#maybe_set_field_attr(field, fieldElt) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/lafcadio/domain.rb', line 78

def maybe_set_field_attr( field, fieldElt )
	setterMethod = "#{ name }="
	if field.respond_to?( setterMethod )
		if value_class != :hash
			if ( attrStr = fieldElt.attributes[name] )
				field.send( setterMethod, value_from_string( attrStr ) )
			end
		else
			if ( attrElt = fieldElt.elements[name] )
				field.send( setterMethod, value_from_elt( attrElt ) )
			end
		end
	end
end

#value_from_elt(elt) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/lafcadio/domain.rb', line 93

def value_from_elt( elt )
	hash = {}
	elt.elements.each( @name.singular ) { |subElt|
		key = subElt.attributes['key'] == 'true'
		value = subElt.text.to_s
		hash[key] = value
	}
	hash
end

#value_from_string(valueStr) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/lafcadio/domain.rb', line 103

def value_from_string( valueStr )
	if @value_class == :integer
		valueStr.to_i
	elsif @value_class == :boolean
		valueStr == 'y'
	elsif @value_class == :enum
		eval ":#{ valueStr }"
	end
end