class NokoBuilder
Attributes
noko[R]
Public Class Methods
new(overwrite={}, noko_options={}) { |self| ... }
click to toggle source
# File lib/noko_builder.rb, line 8 def initialize(overwrite={}, noko_options={}) @overwrite = overwrite @noko = Nokogiri::XML::Builder.new(noko_options) do |xml| @xml = xml yield self end end
Public Instance Methods
method_missing(id, *args, &block)
click to toggle source
# File lib/noko_builder.rb, line 16 def method_missing(id, *args, &block) args = update_value(id, args) args = update_attributes(id, args) args = args.compact.reject(&:blank?) @xml.send(id, *args, &block) if args.present? || block.present? end
Private Instance Methods
update_attributes(id, args)
click to toggle source
# File lib/noko_builder.rb, line 37 def update_attributes(id, args) attributes = @overwrite["#{id}_nattr".to_sym] return args unless attributes.present? args.map do |arg| arg.kind_of?(Hash) ? arg.merge(attributes) : arg end end
update_value(id, args)
click to toggle source
# File lib/noko_builder.rb, line 26 def update_value(id, args) first_arg = args.shift value = @overwrite[id.to_sym] if value.present? first_arg = first_arg.kind_of?(Hash) ? [value, first_arg] : [value] end [first_arg].flatten + args end