Class: DynamicImageSources::SourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/sources/source_factory.rb

Overview

Main source factory provides interface for source classes.

It can also parse any supported source by parsing with all classes inherited from it.

Direct Known Subclasses

ColorSource, GradientSource

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(source) ⇒ Object

Returns source object by parsing with all classes inherited from SourceFactory or nil if there is no factory to parse it.



17
18
19
20
21
22
23
24
25
26
# File 'lib/sources/source_factory.rb', line 17

def self.parse(source)
  raise Exception.new "not implemented in #{self}, but should be" unless self == SourceFactory
  return source if source.is_a? SourceFactory
  source = source.is_a?(Array) ? source.flatten.map(&:to_s).map(&:downcase) : source.to_s.downcase.split(/\s+/)
  @@factories.each do |factory|
    obj = factory.parse source
    return obj if obj
  end
  nil
end

Instance Method Details

#set_source(context, x, y, w, h) ⇒ Object

Interface method for sources to sets them as source.



29
30
31
# File 'lib/sources/source_factory.rb', line 29

def set_source(context, x, y, w, h)
  raise Exception.new "not implemented in #{self.class}, but should be"
end