Class: ShareProgress::VariantParser

Inherits:
Object
  • Object
show all
Defined in:
lib/share_progress/variant_parser.rb

Class Method Summary collapse

Class Method Details

.parse(hash_to_parse) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/share_progress/variant_parser.rb', line 10

def self.parse(hash_to_parse)
  keys = hash_to_parse.keys.map(&:to_sym)
  match = nil
  [FacebookVariant, EmailVariant, TwitterVariant].each do |variant_class|
    if (keys & variant_class.fields).size > 0 # & is array intersection
      raise CouldNotParseVariant unless match.nil? # only match one class
      match = variant_class
    end
  end
  raise CouldNotParseVariant if match.nil?
  match
end