Class: Bmg::OutputPreferences
- Inherits:
-
Object
- Object
- Bmg::OutputPreferences
- Defined in:
- lib/bmg/support/output_preferences.rb
Constant Summary collapse
- DEFAULT_PREFS =
{ attributes_ordering: nil, extra_attributes: :after }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_ordering ⇒ Object
- #extra_attributes ⇒ Object
-
#initialize(options) ⇒ OutputPreferences
constructor
A new instance of OutputPreferences.
- #order_attrlist(attrlist) ⇒ Object
Constructor Details
#initialize(options) ⇒ OutputPreferences
Returns a new instance of OutputPreferences.
9 10 11 |
# File 'lib/bmg/support/output_preferences.rb', line 9 def initialize() @options = DEFAULT_PREFS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/bmg/support/output_preferences.rb', line 12 def @options end |
Class Method Details
.dress(arg) ⇒ Object
14 15 16 17 18 |
# 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 |
Instance Method Details
#attributes_ordering ⇒ Object
20 21 22 |
# File 'lib/bmg/support/output_preferences.rb', line 20 def attributes_ordering [:attributes_ordering] end |
#extra_attributes ⇒ Object
24 25 26 |
# File 'lib/bmg/support/output_preferences.rb', line 24 def extra_attributes [:extra_attributes] end |
#order_attrlist(attrlist) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |