Class: Bmg::OutputPreferences
- Inherits:
-
Object
- Object
- Bmg::OutputPreferences
- Defined in:
- lib/bmg/support/output_preferences.rb
Constant Summary collapse
- DEFAULT_PREFS =
{ attributes_ordering: nil, tuple_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
- #erase_redundance_in_group(before, current) ⇒ Object
- #extra_attributes ⇒ Object
- #grouping_attributes ⇒ Object
-
#initialize(options) ⇒ OutputPreferences
constructor
A new instance of OutputPreferences.
- #order_attrlist(attrlist) ⇒ Object
- #tuple_ordering ⇒ Object
Constructor Details
#initialize(options) ⇒ OutputPreferences
Returns a new instance of OutputPreferences.
10 11 12 |
# File 'lib/bmg/support/output_preferences.rb', line 10 def initialize() @options = DEFAULT_PREFS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/bmg/support/output_preferences.rb', line 13 def @options end |
Class Method Details
.dress(arg) ⇒ Object
15 16 17 18 19 |
# File 'lib/bmg/support/output_preferences.rb', line 15 def self.dress(arg) return arg if arg.is_a?(OutputPreferences) arg = {} if arg.nil? new(arg) end |
Instance Method Details
#attributes_ordering ⇒ Object
27 28 29 |
# File 'lib/bmg/support/output_preferences.rb', line 27 def attributes_ordering [:attributes_ordering] end |
#erase_redundance_in_group(before, current) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bmg/support/output_preferences.rb', line 39 def erase_redundance_in_group(before, current) return [nil, current] unless ga = grouping_attributes return [current, current] unless before new_before, new_current = current.dup, current.dup ga.each do |attr| return [new_before, new_current] unless before[attr] == current[attr] new_current[attr] = nil end [new_before, new_current] end |
#extra_attributes ⇒ Object
31 32 33 |
# File 'lib/bmg/support/output_preferences.rb', line 31 def extra_attributes [:extra_attributes] end |
#grouping_attributes ⇒ Object
35 36 37 |
# File 'lib/bmg/support/output_preferences.rb', line 35 def grouping_attributes [:grouping_attributes] end |
#order_attrlist(attrlist) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bmg/support/output_preferences.rb', line 51 def order_attrlist(attrlist) return attrlist if attributes_ordering.nil? index = Hash[attributes_ordering.each_with_index.to_a] base = attrlist base = attrlist & attributes_ordering if extra_attributes == :ignored base.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 |