Class: AD::Framework::Fields
- Inherits:
-
Hash
- Object
- Hash
- AD::Framework::Fields
- Defined in:
- lib/ad-framework/fields.rb
Instance Method Summary collapse
- #[](lookup) ⇒ Object
- #[]=(lookup, value) ⇒ Object
- #changes ⇒ Object
-
#initialize(ldap_entry) ⇒ Fields
constructor
A new instance of Fields.
- #inspect ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(ldap_entry) ⇒ Fields
Returns a new instance of Fields.
6 7 8 9 10 11 12 |
# File 'lib/ad-framework/fields.rb', line 6 def initialize(ldap_entry) super() @changed_keys = Set.new (ldap_entry || {}).each do |ldap_name, value| self[ldap_name.to_s] = value end end |
Instance Method Details
#[](lookup) ⇒ Object
14 15 16 |
# File 'lib/ad-framework/fields.rb', line 14 def [](lookup) super(lookup.to_s) end |
#[]=(lookup, value) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ad-framework/fields.rb', line 17 def []=(lookup, value) if self[lookup] != value @changed_keys << lookup.to_s end super(lookup.to_s, value) end |
#changes ⇒ Object
24 25 26 |
# File 'lib/ad-framework/fields.rb', line 24 def changes @changed_keys.inject({}){|h, k| h.merge({ k => self[k] }) } end |
#inspect ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/ad-framework/fields.rb', line 32 def inspect max_key_length = (self.keys.collect(&:size).max || 0) + 1 display = self.collect do |(key, value)| key_label = "#{key}:".rjust(max_key_length, ' ') [ key_label, value.inspect ].join(" ") end "\n#{display.join("\n")}" end |
#to_hash ⇒ Object
28 29 30 |
# File 'lib/ad-framework/fields.rb', line 28 def to_hash self.inject({}){|h, (k,v)| h.merge({ k => v }) } end |