class Bmg::OutputPreferences

Constants

DEFAULT_PREFS

Attributes

options[R]

Public Class Methods

dress(arg) click to toggle source
# File lib/bmg/support/output_preferences.rb, line 14
def self.dress(arg)
  return arg if arg.is_a?(OutputPreferences)
  arg = {} if arg.nil?
  new(arg)
end
new(options) click to toggle source
# File lib/bmg/support/output_preferences.rb, line 9
def initialize(options)
  @options = DEFAULT_PREFS.merge(options)
end

Public Instance Methods

attributes_ordering() click to toggle source
# File lib/bmg/support/output_preferences.rb, line 20
def attributes_ordering
  options[:attributes_ordering]
end
extra_attributes() click to toggle source
# File lib/bmg/support/output_preferences.rb, line 24
def extra_attributes
  options[:extra_attributes]
end
order_attrlist(attrlist) click to toggle source
# File lib/bmg/support/output_preferences.rb, line 28
def order_attrlist(attrlist)
  return attrlist if attributes_ordering.nil?
  index = Hash[attributes_ordering.each_with_index.to_a]
  attrlist.sort{|a,b|
    ai, bi = index[a], index[b]
    if ai && bi
      ai <=> bi
    elsif ai
      extra_attributes == :after ? -1 : 1
    else
      extra_attributes == :after ? 1 : -1
    end
  }
end