Class: FormatR::FormatEntry

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

Overview

This class holds a single block of text, either something unchanging or a picture element of some format.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val, unchanging) ⇒ FormatEntry

Returns a new instance of FormatEntry.



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/formatr.rb', line 434

def initialize (val, unchanging)
  @unchanging = unchanging
  @val = val
  unless (unchanging)
    s = val.size - 1
    
    if (val =~ /[@^][<]{#{s},#{s}}/)
      @formatter = LeftFormatter.new(val)
    elsif (val =~ /[@^][>]{#{s},#{s}}/)     
      @formatter = RightFormatter.new(val)
    elsif (val =~ /[@^][\|]{#{s},#{s}}/)
      @formatter = CenterFormatter.new(val)
    elsif (val =~ /[@^](#*)([\.]{0,1})(#*)([eEgG])(#+)/)
      @formatter = ScientificNotationFormatter.new($1, $2, $3, $4, $5)
    elsif (val =~ /[@^](#*)([\.]{0,1})(#*)/)
      @formatter = NumberFormatter.new($1, $2, $3)
    else
      raise FormatException.new(), "Malformed format entry \"#{@val}\""
    end
  end
end

Instance Attribute Details

#unchangingObject

Returns the value of attribute unchanging.



432
433
434
# File 'lib/formatr.rb', line 432

def unchanging
  @unchanging
end

#valObject

Returns the value of attribute val.



432
433
434
# File 'lib/formatr.rb', line 432

def val
  @val
end

Instance Method Details

#formatString(string, var_name = nil, aBinding = nil) ⇒ Object

give back the string passed through the appropriate formatter



462
463
464
465
# File 'lib/formatr.rb', line 462

def formatString (string, var_name=nil, aBinding=nil)
  result = @formatter.formatString(string, var_name, aBinding)
  return result
end

#isUnchanging?Boolean

is this just unchanging characters

Returns:

  • (Boolean)


457
458
459
# File 'lib/formatr.rb', line 457

def isUnchanging? ()
  return @unchanging
end

#to_sObject

show our values



468
469
470
471
472
# File 'lib/formatr.rb', line 468

def to_s ()
  output =  "'" + @val + "'   unchanging:" + @unchanging.to_s
  #(output << " formatter:" + @formatter.class.to_s) if (!@unchanging)
  output
end