Class: Nfe::Helpers::XmlModel::AttributeBase
- Inherits:
-
Object
- Object
- Nfe::Helpers::XmlModel::AttributeBase
- Defined in:
- lib/nfe/helpers/xml_model/attribute_base.rb
Direct Known Subclasses
AttributeBigdecimal, AttributeCollection, AttributeDate, AttributeDatetime, AttributeEnumerize, AttributeFloat, AttributeInteger, AttributeNode, AttributeNodeattribute, AttributeText
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
-
#xml_alias ⇒ Object
Returns the value of attribute xml_alias.
Instance Method Summary collapse
- #add_to_xml(context, xml, attribute) ⇒ Object
-
#initialize(name, options = {}) ⇒ AttributeBase
constructor
A new instance of AttributeBase.
- #parse(context, doc) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ AttributeBase
Returns a new instance of AttributeBase.
7 8 9 10 11 12 13 14 15 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 7 def initialize(name, ={}) @name = name @type = [:type] || :text @required = [:required] @format = [:format] @klass = [:klass] @xml_alias = ([:xml_alias] || @name).to_s end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 5 def format @format end |
#klass ⇒ Object
Returns the value of attribute klass.
5 6 7 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 5 def klass @klass end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 5 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 5 def type @type end |
#xml_alias ⇒ Object
Returns the value of attribute xml_alias.
5 6 7 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 5 def xml_alias @xml_alias end |
Instance Method Details
#add_to_xml(context, xml, attribute) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 22 def add_to_xml(context, xml, attribute) attribute = attr_accessor_value(context, attribute) if !attribute.present? xml.tag!(xml_alias) if required? else add_tag(xml, attribute) end end |
#parse(context, doc) ⇒ Object
17 18 19 20 |
# File 'lib/nfe/helpers/xml_model/attribute_base.rb', line 17 def parse(context, doc) value = xml_value(doc) context.send("#{name}=", get_value(value)) if value.present? end |