Class: MemeCaptain::CaptionChoice
- Inherits:
-
Object
- Object
- MemeCaptain::CaptionChoice
- Includes:
- Comparable
- Defined in:
- lib/meme_captain/caption_choice.rb
Overview
For comparing different caption line break and pointsize choices.
Instance Attribute Summary collapse
-
#bound_height ⇒ Object
Returns the value of attribute bound_height.
-
#bound_width ⇒ Object
Returns the value of attribute bound_width.
-
#metrics ⇒ Object
Returns the value of attribute metrics.
-
#pointsize ⇒ Object
Returns the value of attribute pointsize.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #fits ⇒ Object
- #fits_i ⇒ Object
-
#initialize(pointsize, metrics, text, bound_width, bound_height) ⇒ CaptionChoice
constructor
A new instance of CaptionChoice.
- #num_lines ⇒ Object
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_height ⇒ Object
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_width ⇒ Object
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 |
#metrics ⇒ Object
Returns the value of attribute metrics.
36 37 38 |
# File 'lib/meme_captain/caption_choice.rb', line 36 def metrics @metrics end |
#pointsize ⇒ Object
Returns the value of attribute pointsize.
35 36 37 |
# File 'lib/meme_captain/caption_choice.rb', line 35 def pointsize @pointsize end |
#text ⇒ Object
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 |
#fits ⇒ Object
21 22 23 |
# File 'lib/meme_captain/caption_choice.rb', line 21 def fits metrics.width <= bound_width && metrics.height <= bound_height end |
#fits_i ⇒ Object
25 26 27 |
# File 'lib/meme_captain/caption_choice.rb', line 25 def fits_i fits ? 1 : 0 end |
#num_lines ⇒ Object
17 18 19 |
# File 'lib/meme_captain/caption_choice.rb', line 17 def num_lines text.count("\n") + 1 end |