Class: IMS::LTI::Serializers::Base::Filter
- Inherits:
-
Object
- Object
- IMS::LTI::Serializers::Base::Filter
- Defined in:
- lib/ims/lti/serializers/base.rb
Instance Method Summary collapse
- #add_filter(name, opts = {}) ⇒ Object
- #filter(hash) ⇒ Object
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #options_for_attribute(attribute) ⇒ Object
Constructor Details
#initialize ⇒ Filter
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 (attribute) = {} [:optional] = @optionals.include?(attribute) ? true : false [:key] = @keys[attribute] [:has_serializable] = @serializables.include?(attribute) ? true : false [:has_list_of_serializables] = @serializable_lists.include?(attribute) ? true : false end |