Class: IMS::LTI::Serializers::Base::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/ims/lti/serializers/base.rb

Instance Method Summary collapse

Constructor Details

#initializeFilter

Returns a new instance of Filter.



4
5
6
7
8
9
# File 'lib/ims/lti/serializers/base.rb', line 4

def initialize
  @optionals = Set.new
  @keys = {}
  @serializables = Set.new
  @serializable_lists = Set.new
end

Instance Method Details

#add_filter(name, opts = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/ims/lti/serializers/base.rb', line 11

def add_filter(name, opts={})
  @optionals.add(name) if opts[:optional]
  @keys[name] = opts[:key] if opts[:key]
  @serializables.add(name) if opts[:serializable]
  @serializable_lists.add(name) if opts[:list_of_serializables]
end

#filter(hash) ⇒ Object



27
28
29
30
31
32
# File 'lib/ims/lti/serializers/base.rb', line 27

def filter(hash)
  hash = optionals(hash)
  hash = serializables(hash)
  hash = serializable_lists(hash)
  keys(hash) # Needs to happen last
end

#options_for_attribute(attribute) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/ims/lti/serializers/base.rb', line 18

def options_for_attribute(attribute)
  options = {}
  options[:optional] = @optionals.include?(attribute) ? true : false
  options[:key] = @keys[attribute]
  options[:has_serializable] = @serializables.include?(attribute) ? true : false
  options[:has_list_of_serializables] = @serializable_lists.include?(attribute) ? true : false
  options
end