Class: Lisp::Format::Directives::Plural

Inherits:
Directive show all
Defined in:
lib/carat/lisp-format.rb

Overview

Represents the ~R (Plural) directive. It outputs English plural suffixes depending on the given argument.

Instance Attribute Summary

Attributes inherited from Directive

#pos

Instance Method Summary collapse

Methods inherited from Directive

#initialize, #join

Constructor Details

This class inherits a constructor from Lisp::Format::Directives::Directive

Instance Method Details

#execute(state) ⇒ Object

Outputs the given argument as an English plural suffix depending on the arguments value. If arg is not #eql? to 1, a lowercase s is output, else nothing is output. The meaning of modifiers are:

:

backs up one argument before checking,

@

outputs y or ies instead of s and nothing,

:@

a combination of the two above.



907
908
909
910
911
912
913
914
# File 'lib/carat/lisp-format.rb', line 907

def execute(state)
  arg = colon_mod? ? state.previous_arg : state.next_arg
  if at_mod?
    state.output((arg.eql? 1) ? 'y' : 'ies')
  else
    state.output(?s) unless arg.eql? 1
  end
end