Class: Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/surpass/formatting.rb

Constant Summary collapse

HORZ_GENERAL =
0x00
HORZ_LEFT =
0x01
HORZ_CENTER =
0x02
HORZ_RIGHT =
0x03
HORZ_FILLED =
0x04
HORZ_JUSTIFIED =

BIFF4-BIFF8X

0x05
HORZ_CENTER_ACROSS_SEL =

Centred across selection (BIFF4-BIFF8X)

0x06
HORZ_DISTRIBUTED =

Distributed (BIFF8X)

0x07
VERT_TOP =
0x00
VERT_CENTER =
0x01
VERT_BOTTOM =
0x02
VERT_JUSTIFIED =

Justified (BIFF5-BIFF8X)

0x03
VERT_DISTRIBUTED =

Distributed (BIFF8X)

0x04
DIRECTION_GENERAL =

BIFF8X

0x00
DIRECTION_LR =
0x01
DIRECTION_RL =
0x02
ORIENTATION_NOT_ROTATED =
0x00
ORIENTATION_STACKED =
0x01
ORIENTATION_90_CC =
0x02
ORIENTATION_90_CW =
0x03
ROTATION_0_ANGLE =
0x00
ROTATION_STACKED =
0xFF
WRAP_AT_RIGHT =
0x01
NOT_WRAP_AT_RIGHT =
0x00
SHRINK_TO_FIT =
0x01
NOT_SHRINK_TO_FIT =
0x00

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Alignment

Returns a new instance of Alignment.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/surpass/formatting.rb', line 279

def initialize(hash = {})
  # Initialize to defaults.
  @horz = HORZ_GENERAL
  @vert = VERT_BOTTOM
  @wrap = NOT_WRAP_AT_RIGHT
  @dire = DIRECTION_GENERAL
  @orie = ORIENTATION_NOT_ROTATED
  @rota = ROTATION_0_ANGLE
  @shri = NOT_SHRINK_TO_FIT
  @inde = 0
  @merg = 0
  
  # Allow defaults to be overridden in hash. Where there is no :align key in hash,
  # this just leaves the default value in place.
  self.align = hash[:align]
  self.wrap = hash[:wrap]
end

Instance Attribute Details

#direObject

Returns the value of attribute dire.



270
271
272
# File 'lib/surpass/formatting.rb', line 270

def dire
  @dire
end

#horzObject

Returns the value of attribute horz.



268
269
270
# File 'lib/surpass/formatting.rb', line 268

def horz
  @horz
end

#indeObject

Returns the value of attribute inde.



274
275
276
# File 'lib/surpass/formatting.rb', line 274

def inde
  @inde
end

#mergObject

Returns the value of attribute merg.



275
276
277
# File 'lib/surpass/formatting.rb', line 275

def merg
  @merg
end

#orieObject

Returns the value of attribute orie.



271
272
273
# File 'lib/surpass/formatting.rb', line 271

def orie
  @orie
end

#rotaObject

Returns the value of attribute rota.



272
273
274
# File 'lib/surpass/formatting.rb', line 272

def rota
  @rota
end

#shriObject

Returns the value of attribute shri.



273
274
275
# File 'lib/surpass/formatting.rb', line 273

def shri
  @shri
end

#vertObject

Returns the value of attribute vert.



269
270
271
# File 'lib/surpass/formatting.rb', line 269

def vert
  @vert
end

#wrapObject

Returns the value of attribute wrap.



277
278
279
# File 'lib/surpass/formatting.rb', line 277

def wrap
  @wrap
end

Instance Method Details

#align=(alignment_directives) ⇒ Object

Don’t support passing constants here because :horz and :vert are exposed so if someone wants to use nasty HORZ_RIGHT they can do align.vert = HORZ_RIGHT



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/surpass/formatting.rb', line 299

def align=(alignment_directives)
  if alignment_directives =~ /\s/
    args = alignment_directives.split
  else
    args = [alignment_directives] # there's just 1 here
  end
  
  args.each do |a|
    case a
    when 'right'
      @horz = HORZ_RIGHT
    when 'left'
      @horz = HORZ_LEFT
    when 'center', 'centre'
      @horz = HORZ_CENTER
    when 'general'
      @horz = HORZ_GENERAL
    when 'filled'
      @horz = HORZ_FILLED
    when 'justify'
      @horz = HORZ_JUSTIFIED
    when 'top'
      @vert = VERT_TOP
    when 'middle'
      @vert = VERT_CENTER
    when 'bottom'
      @vert = VERT_BOTTOM
    when nil
      # Do nothing.
    else
      raise "I don't know how to set align to #{a.inspect}."
    end
  end
end