Class: MemeCaptain::CaptionChoice

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/meme_captain/caption_choice.rb

Overview

For comparing different caption line break and pointsize choices.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointsize, metrics, text, bound_width, bound_height) ⇒ CaptionChoice

Returns a new instance of CaptionChoice.



9
10
11
12
13
14
15
# File 'lib/meme_captain/caption_choice.rb', line 9

def initialize(pointsize, metrics, text, bound_width, bound_height)
  @pointsize = pointsize
  @metrics = metrics
  @text = text
  @bound_width = bound_width
  @bound_height = bound_height
end

Instance Attribute Details

#bound_heightObject

Returns the value of attribute bound_height.



39
40
41
# File 'lib/meme_captain/caption_choice.rb', line 39

def bound_height
  @bound_height
end

#bound_widthObject

Returns the value of attribute bound_width.



38
39
40
# File 'lib/meme_captain/caption_choice.rb', line 38

def bound_width
  @bound_width
end

#metricsObject

Returns the value of attribute metrics.



36
37
38
# File 'lib/meme_captain/caption_choice.rb', line 36

def metrics
  @metrics
end

#pointsizeObject

Returns the value of attribute pointsize.



35
36
37
# File 'lib/meme_captain/caption_choice.rb', line 35

def pointsize
  @pointsize
end

#textObject

Returns the value of attribute text.



37
38
39
# File 'lib/meme_captain/caption_choice.rb', line 37

def text
  @text
end

Instance Method Details

#<=>(other) ⇒ Object



29
30
31
32
33
# File 'lib/meme_captain/caption_choice.rb', line 29

def <=>(other)
  [fits_i, pointsize, fits ? -num_lines : num_lines] <=>
    [other.fits_i, other.pointsize,
    other.fits ? -other.num_lines : other.num_lines]
end

#fitsObject



21
22
23
# File 'lib/meme_captain/caption_choice.rb', line 21

def fits
  metrics.width <= bound_width && metrics.height <= bound_height
end

#fits_iObject



25
26
27
# File 'lib/meme_captain/caption_choice.rb', line 25

def fits_i
  fits ? 1 : 0
end

#num_linesObject



17
18
19
# File 'lib/meme_captain/caption_choice.rb', line 17

def num_lines
  text.count("\n") + 1
end