Sha256: 9573684debe31a7c0b05860f755bbcacc6baa54acb27e5fa223316638715b2f3

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 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 'writer/fetcher-microdata/person_user'
require 'writer/fetcher-microdata/article_small'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fetcher-microdata-0.0.1 lib/fetcher-microdata.rb