Class: Yearbook::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/yearbook/image.rb

Constant Summary collapse

CLIPPER_REGEX =

META STUFF

/^(clip_and_print(?:_best)?|clip)_(\w+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname) ⇒ Image

Returns a new instance of Image.



9
10
11
# File 'lib/yearbook/image.rb', line 9

def initialize(fname)
  @filename = fname      
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(foo, *args, &blk) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/yearbook/image.rb', line 57

def method_missing(foo, *args, &blk)
  f = foo.to_s
  # e.g. clip_faces
  if f =~ CLIPPER_REGEX
    self.send $1, $2, *args, &blk
  else
    super
  end
end

Instance Attribute Details

#clipsObject (readonly)

Returns the value of attribute clips.



8
9
10
# File 'lib/yearbook/image.rb', line 8

def clips
  @clips
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/yearbook/image.rb', line 8

def filename
  @filename
end

Instance Method Details

#clip(obj_type, *args, &blk) ⇒ Object

args is empty for now…



16
17
18
# File 'lib/yearbook/image.rb', line 16

def clip(obj_type, *args, &blk)
  @clips = detect_and_collect(cv_image, obj_type)
end

#clip_and_print(obj_type, filename, *args, &blk) ⇒ Object

convenience method



40
41
42
43
44
# File 'lib/yearbook/image.rb', line 40

def clip_and_print(obj_type, filename, *args, &blk)
  clip(obj_type, *args, &blk)

  print_clips(filename)
end

#clip_and_print_best(obj_type, filename, *args, &blk) ⇒ Object

convenience method



47
48
49
50
51
# File 'lib/yearbook/image.rb', line 47

def clip_and_print_best(obj_type, filename, *args, &blk)
  clip(obj_type, *args, &blk)

  print_best_clip(filename)
end

#clipped?Boolean

Returns:

  • (Boolean)


23
# File 'lib/yearbook/image.rb', line 23

def clipped?; @clips.count > 0; end

just the original image



26
27
28
# File 'lib/yearbook/image.rb', line 26

def print(fname, &blk)
  write_images(magick_image, fname, &blk)
end


35
36
37
# File 'lib/yearbook/image.rb', line 35

def print_best_clip(fname, &blk)
  write_images(constitute_best_clip, fname, &blk)
end

print all the clips



31
32
33
# File 'lib/yearbook/image.rb', line 31

def print_clips(fname, &blk)
  write_images(constitute_clips, fname, &blk)
end

#respond_to?(foo, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/yearbook/image.rb', line 67

def respond_to?(foo, include_private=false)
  return foo.to_s =~ CLIPPER_REGEX ? true : super(foo, include_private)
end