Class: Lafcadio::ClassDefinitionXmlParser::FieldAttribute
- Inherits:
-
Object
- Object
- Lafcadio::ClassDefinitionXmlParser::FieldAttribute
- Defined in:
- lib/lafcadio/domain.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value_class ⇒ Object
readonly
Returns the value of attribute value_class.
Instance Method Summary collapse
-
#initialize(name, value_class, objectFieldClass = nil) ⇒ FieldAttribute
constructor
A new instance of FieldAttribute.
- #maybe_set_field_attr(field, fieldElt) ⇒ Object
- #value_from_elt(elt) ⇒ Object
- #value_from_string(valueStr) ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
71 72 73 |
# File 'lib/lafcadio/domain.rb', line 71 def name @name end |
#value_class ⇒ Object (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 |