class Hbci::ElementGroup
Attributes
defined_elements[RW]
elements[RW]
Public Class Methods
element(name, definition = {})
click to toggle source
# File lib/hbci/element_group.rb, line 15 def self.element(name, definition = {}) elements_to_be_defined << definition.merge(name: name) end
elements_to_be_defined()
click to toggle source
# File lib/hbci/element_group.rb, line 11 def self.elements_to_be_defined @elements_to_be_defined ||= [] end
new()
click to toggle source
# File lib/hbci/element_group.rb, line 39 def initialize @defined_elements = [] @elements = [] define_elements end
Public Instance Methods
define_element(definition)
click to toggle source
# File lib/hbci/element_group.rb, line 27 def define_element(definition) defined_elements << definition apply_element_default(definition) end
define_elements()
click to toggle source
# File lib/hbci/element_group.rb, line 23 def define_elements self.class.elements_to_be_defined.each { |el| define_element(el) } end
element(name, definition = {})
click to toggle source
# File lib/hbci/element_group.rb, line 19 def element(name, definition = {}) define_element(definition.merge(name: name)) end
respond_to?(name, include_all = false)
click to toggle source
Calls superclass method
# File lib/hbci/element_group.rb, line 46 def respond_to?(name, include_all = false) potential_element_name = name.to_s.split('=').first.to_sym index_for_element(potential_element_name) || super end
to_s()
click to toggle source
# File lib/hbci/element_group.rb, line 32 def to_s element_strings = elements.each_with_index.map do |element, index| ElementUnparser.new(element, defined_elements[index][:type]).unparse end element_strings.join(':').gsub(/:*$/, '') end
Private Instance Methods
apply_element_default(definition)
click to toggle source
# File lib/hbci/element_group.rb, line 82 def apply_element_default(definition) if definition[:default].is_a?(Proc) set_element(definition[:name], definition[:default].call(self)) else set_element(definition[:name], definition[:default]) end end
get_element(name)
click to toggle source
# File lib/hbci/element_group.rb, line 54 def get_element(name) elements[index_for_element(name)] end
index_for_element(name)
click to toggle source
# File lib/hbci/element_group.rb, line 90 def index_for_element(name) defined_elements.index { |el| el[:name] == name } end
method_missing(name, *args)
click to toggle source
Calls superclass method
# File lib/hbci/element_group.rb, line 62 def method_missing(name, *args) potential_element_name = name.to_s.split('=').first.to_sym is_writer = (name[-1..-1] == '=') index = index_for_element(potential_element_name) if index return set_element(potential_element_name, args.first) if is_writer && args.count == 1 return get_element(potential_element_name) end super end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/hbci/element_group.rb, line 76 def respond_to_missing?(method_name, include_private = false) potential_element_name = method_name.to_s.split('=').first.to_sym index_for_element(potential_element_name) || super end
set_element(name, value)
click to toggle source
# File lib/hbci/element_group.rb, line 58 def set_element(name, value) elements[index_for_element(name)] = value end