Class: FormatR::FormatEntry
- Inherits:
-
Object
- Object
- FormatR::FormatEntry
- 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
-
#unchanging ⇒ Object
Returns the value of attribute unchanging.
-
#val ⇒ Object
Returns the value of attribute val.
Instance Method Summary collapse
-
#formatString(string, var_name = nil, aBinding = nil) ⇒ Object
give back the string passed through the appropriate formatter.
-
#initialize(val, unchanging) ⇒ FormatEntry
constructor
A new instance of FormatEntry.
-
#isUnchanging? ⇒ Boolean
is this just unchanging characters.
-
#to_s ⇒ Object
show our values.
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
#unchanging ⇒ Object
Returns the value of attribute unchanging.
432 433 434 |
# File 'lib/formatr.rb', line 432 def unchanging @unchanging end |
#val ⇒ Object
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
457 458 459 |
# File 'lib/formatr.rb', line 457 def isUnchanging? () return @unchanging end |
#to_s ⇒ Object
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 |