Class: FormatText::Effector
- Inherits:
-
Object
- Object
- FormatText::Effector
- Defined in:
- lib/fto.rb
Overview
Class used to describe a format effector. The FormatText::Effector class is basically a container rather than an active class. It holds information about how an effector operates and what it needs.
Typically FormatText::Effector objects aren’t created directly, but by calling FTO.registerEffector().
Constant Summary collapse
- @@NEXTID =
1
Instance Attribute Summary collapse
-
#category ⇒ Object
String.
-
#code ⇒ Object
Proc.
-
#data ⇒ Object
Array.
-
#description ⇒ Object
String.
-
#dValue ⇒ Object
Any.
-
#dWidth ⇒ Object
Various.
-
#enabled ⇒ Object
Boolean.
-
#fill ⇒ Object
String.
-
#id ⇒ Object
readonly
Fixnum.
-
#justify ⇒ Object
Symbol.
-
#mask ⇒ Object
Integer.
-
#name ⇒ Object
String.
-
#priority ⇒ Object
Fixnum.
-
#reExtra ⇒ Object
String.
-
#reMatch ⇒ Object
String.
-
#signbit ⇒ Object
Integer.
-
#sortKey ⇒ Object
String.
-
#syntax ⇒ Object
String.
-
#truncate ⇒ Object
Symbol.
Instance Method Summary collapse
-
#disable ⇒ Object
Disables the effector, removing it from consideration when the format string is being scanned.
-
#disabled? ⇒ Boolean
Returns
trueif the effector is disabled (i.e., inactive and not considered when scanning the format string); otherwise returnsfalse. -
#enable ⇒ Object
Enables the effector, making certain that it is considered when the format string is being scanned.
-
#enabled? ⇒ Boolean
Returns
trueif the effector is enabled (i.e., active and considered when scanning the format string); otherwise returnsfalse. -
#initialize(*argsp) ⇒ Effector
constructor
Creates a new FormatText::Effector object.
Constructor Details
#initialize(*argsp) ⇒ Effector
Creates a new FormatText::Effector object. The argument list can be either an order-dependent list of attribute values, or a hash using the symbolised attribute names as the keys.
call-seq:
new<i>(Hash)</i> => <i>FormatText::Effector object</i>
new<i>(name, description, enabled, priority, code, reMatch, reExtra, mask, signbit, dWidth, fill, justify, truncate, data)</i> => <i>FormatText::Effector object</i>
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/fto.rb', line 642 def initialize(*argsp) @id = @@NEXTID @@NEXTID += 1 # # Set up defaults # (@name, @description, @code, @reMatch, @reExtra, @mask, @signbit, @dWidth, @dValue, @truncate) = nil @enabled = true @priority = 1000 @data = [] @fill = ' ' @justify = :left # # We can either handle an order-dependent list of arguments, or # a hash representing keyword arguments. # args = (argsp.length == 1) ? argsp[0] : argsp case args.class when Array (@name, @description, @enabled, @priority, @code, @reMatch, @reExtra, @mask, @signbit, @dWidth, @fill, @justify, @truncate, @data) = args when Hash args.each { |key,val| eval("@{key.to_s} = val") } end @data = [@data] unless (@data.nil? || (@data.class == Array)) end |
Instance Attribute Details
#category ⇒ Object
String. Phrase for grouping with related effectors in documentation (like ‘String Insertion’ or ‘Numeric Conversion’).
527 528 529 |
# File 'lib/fto.rb', line 527 def category @category end |
#code ⇒ Object
Proc. Code block (e.g., a lambda function) that actually interprets the effector. (See the FormatText::Context class for a description, or the various Convert constants in the source.)
631 632 633 |
# File 'lib/fto.rb', line 631 def code @code end |
#data ⇒ Object
Array. Array of additional info for the function (effector-specific).
623 624 625 |
# File 'lib/fto.rb', line 623 def data @data end |
#description ⇒ Object
String. Human-readable brief description.
537 538 539 |
# File 'lib/fto.rb', line 537 def description @description end |
#dValue ⇒ Object
Any. Default value (used if argList has been exhausted).
597 598 599 |
# File 'lib/fto.rb', line 597 def dValue @dValue end |
#dWidth ⇒ Object
Various. Default width for the effector result (used for documentation and when filling). Possible values:
- Integer
-
Specified number of columns.
- String
-
The string is used in the documentation verbatim.
:NA-
Default width not applicable to this effector.
:asNeeded-
As many columns as are needed to represent the value.
:asSpecified-
As specified in the effector.
This should be set to an integer value if needed by the effector function. All of the other possible values shown above are used in generating documentation.
592 593 594 |
# File 'lib/fto.rb', line 592 def dWidth @dWidth end |
#enabled ⇒ Object
Boolean. Whether this effector should be processed or ignored.
515 516 517 |
# File 'lib/fto.rb', line 515 def enabled @enabled end |
#fill ⇒ Object
String. Character used to fill values shorter than the field widths.
603 604 605 |
# File 'lib/fto.rb', line 603 def fill @fill end |
#id ⇒ Object (readonly)
Fixnum. ID number assigned to the effector, unique within a usage environment. Used by FTO.enableEffector(), FTO.disableEffector(), and FTO.destroyEffector().
509 510 511 |
# File 'lib/fto.rb', line 509 def id @id end |
#justify ⇒ Object
Symbol. Symbol value :left or :right, indicating against which edge of a too-wide field the value should abut.
610 611 612 |
# File 'lib/fto.rb', line 610 def justify @justify end |
#mask ⇒ Object
Integer. [Numeric conversion effectors only] If the effector is used to represent a number, this is a mask of the bits to be included. For instance, if the effector only displays 8-bit values, this value would be 0xFF.
568 569 570 |
# File 'lib/fto.rb', line 568 def mask @mask end |
#name ⇒ Object
String. Human-readable name for what the effector does. Used for sorting.
521 522 523 |
# File 'lib/fto.rb', line 521 def name @name end |
#priority ⇒ Object
Fixnum. Numeric priority value for sorting purposes.
542 543 544 |
# File 'lib/fto.rb', line 542 def priority @priority end |
#reExtra ⇒ Object
String. Optional regex pattern used to extract additional info (such as a field width).
560 561 562 |
# File 'lib/fto.rb', line 560 def reExtra @reExtra end |
#reMatch ⇒ Object
String. Regular expression used to recognise the effector in the format string.
554 555 556 |
# File 'lib/fto.rb', line 554 def reMatch @reMatch end |
#signbit ⇒ Object
Integer. [Numeric conversion effectors only] If the value is to be interpreted as signed, this is a mask for the sign bit. (For a byte, :mask would be 0xFF and :signbit would be 0x80.)
576 577 578 |
# File 'lib/fto.rb', line 576 def signbit @signbit end |
#sortKey ⇒ Object
String. Key used to sort effectors, built from the name and priority.
548 549 550 |
# File 'lib/fto.rb', line 548 def sortKey @sortKey end |
#syntax ⇒ Object
String. Human-readable syntax (HTML okey).
532 533 534 |
# File 'lib/fto.rb', line 532 def syntax @syntax end |
#truncate ⇒ Object
Symbol. Symbol value :left or :right indicating on which side too-wide results should be truncated to fit within the field width.
617 618 619 |
# File 'lib/fto.rb', line 617 def truncate @truncate end |
Instance Method Details
#disable ⇒ Object
Disables the effector, removing it from consideration when the format string is being scanned. It can be subsequently re-enabled with the Effector#enable() method. This is a no-op if the effector is already disabled.
:call-seq:
disable<i>()</i> => <i>nil</i>
680 681 682 683 |
# File 'lib/fto.rb', line 680 def disable() @enabled = false FTO.rebuildEffectorList() end |
#disabled? ⇒ Boolean
Returns true if the effector is disabled (i.e., inactive and not considered when scanning the format string); otherwise returns false.
:call-seq:
disabled? => <i>Boolean</i>
693 694 695 |
# File 'lib/fto.rb', line 693 def disabled?() ! @enabled end |
#enable ⇒ Object
Enables the effector, making certain that it is considered when the format string is being scanned. This is a no-op if the effector is already active.
:call-seq:
enable<i>()</i> => <i>nil</i>
705 706 707 708 |
# File 'lib/fto.rb', line 705 def enable() @enabled = true FTO.rebuildEffectorList() end |
#enabled? ⇒ Boolean
Returns true if the effector is enabled (i.e., active and considered when scanning the format string); otherwise returns false.
:call-seq:
enabled? => <i>Boolean</i>
718 719 720 |
# File 'lib/fto.rb', line 718 def enabled?() @enabled end |