module Bio::NeXML::Mapper::Inflections

String inflections. This module is mixed with the String class.

"targets".singular     #=> "target"
"target".plural        #=> "targets"
"Bio::NeXML::Otu".key  #=> "otu"

Constants

PLURALS
SINGULARS

Public Instance Methods

key() click to toggle source

For a module name as “Bio::NeXML” return “nexml”.

# File lib/bio/db/nexml/mapper/inflection.rb, line 85
def key
  result = self.dup
  if i = rindex( ':' )
    result = self[ i + 1 .. -1 ]
  end
  result.downcase
end
plural() click to toggle source

Return the plural form of a string.

# File lib/bio/db/nexml/mapper/inflection.rb, line 74
def plural
  result = self.dup
  PLURALS.each do |match_exp, replacement_exp|
    unless match(Regexp.compile(match_exp)).nil?
      result =  gsub(Regexp.compile(match_exp), replacement_exp)
    end
  end
  return result
end
singular() click to toggle source

Return the singular form of string.

# File lib/bio/db/nexml/mapper/inflection.rb, line 62
def singular
  result = self.dup
  SINGULARS.each do |match, replace|
    rule = Regexp.compile( match )
    unless match( rule ).nil?
      result = gsub( rule, replace) 
    end
  end
  return result
end