class Nfe::Helpers::XmlModel::AttributeBase
Attributes
format[RW]
klass[RW]
name[RW]
type[RW]
xml_alias[RW]
Public Class Methods
new(name, options={})
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 7 def initialize(name, options={}) @name = name @type = options[:type] || :text @required = options[:required] @format = options[:format] @klass = options[:klass] @xml_alias = (options[:xml_alias] || @name).to_s end
Public Instance Methods
add_to_xml(context, xml, attribute)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
add_element(attribute)
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 37 def add_element(attribute) attribute.to_s end
get_value(value)
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 33 def get_value(value) value.text end
xml_value(doc)
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 41 def xml_value(doc) doc.css(xml_alias).first end
Private Instance Methods
add_tag(xml, attribute)
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 50 def add_tag(xml, attribute) xml.tag!(xml_alias) { |node| node << add_element(attribute) } end
attr_accessor_value(context, attribute)
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 46 def attr_accessor_value(context, attribute) context.send(attribute) end
required?()
click to toggle source
# File lib/nfe/helpers/xml_model/attribute_base.rb, line 54 def required? @required end