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, grouping_attributes: 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
- #grouping_character ⇒ 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.
11 12 13 |
# File 'lib/bmg/support/output_preferences.rb', line 11 def initialize() = DEFAULT_PREFS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/bmg/support/output_preferences.rb', line 14 def end |
Class Method Details
.dress(arg) ⇒ Object
16 17 18 19 20 |
# File 'lib/bmg/support/output_preferences.rb', line 16 def self.dress(arg) return arg if arg.is_a?(OutputPreferences) arg = {} if arg.nil? new(arg) end |
Instance Method Details
#attributes_ordering ⇒ Object
28 29 30 |
# File 'lib/bmg/support/output_preferences.rb', line 28 def attributes_ordering [:attributes_ordering] end |
#erase_redundance_in_group(before, current) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bmg/support/output_preferences.rb', line 44 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| unless before[attr] == current[attr] return [new_before, new_current] end new_current[attr] = grouping_character end [new_before, new_current] end |
#extra_attributes ⇒ Object
32 33 34 |
# File 'lib/bmg/support/output_preferences.rb', line 32 def extra_attributes [:extra_attributes] end |
#grouping_attributes ⇒ Object
36 37 38 |
# File 'lib/bmg/support/output_preferences.rb', line 36 def grouping_attributes [:grouping_attributes] end |
#grouping_character ⇒ Object
40 41 42 |
# File 'lib/bmg/support/output_preferences.rb', line 40 def grouping_character [:grouping_character] end |
#order_attrlist(attrlist) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bmg/support/output_preferences.rb', line 58 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 |
#tuple_ordering ⇒ Object
22 23 24 25 26 |
# File 'lib/bmg/support/output_preferences.rb', line 22 def tuple_ordering return nil unless to = [:tuple_ordering] @tuple_ordering = Ordering.new(to) end |