Sha256: 688fec35847f61438a7b883ea1c40ab1393b2d7f8445d83964c71b1456058951

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 Bytes

Contents

require 'seo_friendly/constructors/meta_constructors'
module SeoFriendly

  class DataExtractor

    attr_reader :source, :title, :description, :keywords

    # a little bit of metaprogramming
    EXTRACTORS = { title: TitleConstructor, description: DescriptionConstructor, keywords: KeyWordsConstructor }

    def initialize(source)
      @source = source
      extract_information
    end

    def seo_attributes
      { title: title, description: description, keywords: keywords }
    end

    private

    def extract_information
      EXTRACTORS.each do |attribute_name, extractor_class|
        instance_variable_set("@#{attribute_name}", extractor_class.send(:extract, source.send(attribute_name)))
      end
    rescue => exception
      raise ExtractDataFromSourceError.new(source.class.name, exception.message)
    end


  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
seo_friendly-0.0.2 lib/seo_friendly/data_extractor.rb
seo_friendly-0.0.1 lib/seo_friendly/data_extractor.rb