Sha256: 6aebb401bbebd1a077405a6a51ad1ab60893fac8c0c87c0d6798171660e1e3a1

Contents?: true

Size: 1.84 KB

Versions: 43

Compression:

Stored size: 1.84 KB

Contents

class UIImage

  # Operator shorthand for `apply_filter`, or coerces the image into other
  # formats.
  #
  # @example
  #   image = 'test'.uiimage
  #   new_image = image | CIFilter.gaussian_blur  # => returns a CIImage
  #   new_image = (image | CIFilter.gaussian_blur).uiimage  # => coerce to UIImage
  #   new_image = image | CIFilter.gaussian_blur | UIImage  # => coerce to UIImage via chaining
  def |(filter)
    if CIFilter === filter
      apply_filter(filter)
    elsif filter == UIImage
      self
    elsif filter == UIView || filter == UIImageView
      self.uiimageview
    elsif filter == CIImage
      ciimage
    elsif filter == UIColor
      uicolor
    elsif filter == NSData
      nsdata
    else
      raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
    end
  end

end


class UIView

   # Applies a filter (to a UIImage representation) or coerces to another format
   def |(filter)
    if filter == UIImage
      self.uiimage
    else
      raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
    end
   end

end


class CIImage

  def |(filter)
    if CIFilter === filter
      apply_filter(filter)
    elsif filter == UIImage
      self.uiimage
    elsif filter == UIView || filter == UIImageView
      self.uiimage.uiimageview
    elsif filter == CIImage
      self
    else
      raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
    end
  end

end


class String

  def |(filter)
    if Regexp === filter
      match = filter.match(self)
      match && match[0]
    elsif String === filter
      self.index(filter) && filter
    else
      raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
    end
  end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
sugarcube-1.4.1 lib/sugarcube-pipes/pipes.rb
sugarcube-1.4.0 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.11 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.10 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.9 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.8 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.7 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.6 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.5 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.4 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.3 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.2 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.1 lib/sugarcube-pipes/pipes.rb
sugarcube-1.3.0 lib/sugarcube-pipes/pipes.rb
sugarcube-1.1.0 lib/sugarcube-pipes/pipes.rb
sugarcube-1.0.7 lib/sugarcube-pipes/pipes.rb
sugarcube-1.0.6 lib/sugarcube-pipes/pipes.rb
sugarcube-1.0.5 lib/sugarcube-pipes/pipes.rb
sugarcube-1.0.4 lib/sugarcube-pipes/pipes.rb
sugarcube-1.0.3 lib/sugarcube-pipes/pipes.rb