Sha256: 16dd688c766655f8c54f4c1a6b62241b37ca2444133394f4600fedf2bc8c6d33

Contents?: true

Size: 1.39 KB

Versions: 9

Compression:

Stored size: 1.39 KB

Contents

require 'discoverer'

module Fetcher
  class Microdata
    include Discoverer::Writer
    include Virtus

    attr_reader :_type
    
    def initialize *arguments
      if arguments.first.is_a? Symbol
        social_network = arguments.shift
        self.attributes = coerce social_network, *arguments
      elsif arguments.first.is_a? Hash
        self.attributes = arguments.first
      end
    end

    def coerce social_network, *raw_data
      begin
        eval("::#{self.class}::#{social_network.to_s.capitalize}::Coercer").call *raw_data
      rescue NameError => e
        if e.message.include? "#{self.class}::#{social_network.to_s.capitalize}"
          raise UnknownSocialNetworkError, 
            "Couldn't find coertion algorithm for '#{social_network}' social network, please require 'fetcher-microdata-#{social_network}' in your project and make sure it has a #{self.class}::#{social_network.to_s.capitalize}::Coercer"
        else
          raise e
        end
      end
    end 

    # Exceptions
    #######################################

    class UnknownSocialNetworkError < StandardError; end
  end
end

require 'fetcher-microdata/version'
require 'fetcher-microdata/person_user'
require 'fetcher-microdata/article_small'
require 'fetcher-microdata/review'

require 'writer/fetcher-microdata/person_user'
require 'writer/fetcher-microdata/article_small'
require 'writer/fetcher-microdata/review'

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fetcher-microdata-0.0.10 lib/fetcher-microdata.rb
fetcher-microdata-0.0.9 lib/fetcher-microdata.rb
fetcher-microdata-0.0.8 lib/fetcher-microdata.rb
fetcher-microdata-0.0.7 lib/fetcher-microdata.rb
fetcher-microdata-0.0.6 lib/fetcher-microdata.rb
fetcher-microdata-0.0.5 lib/fetcher-microdata.rb
fetcher-microdata-0.0.4 lib/fetcher-microdata.rb
fetcher-microdata-0.0.3 lib/fetcher-microdata.rb
fetcher-microdata-0.0.2 lib/fetcher-microdata.rb