class SimpleSymbolize::Translations

The translations class holds the attributes used to transform a String object. It also provides helper methods to manipulate those attributes.

Attributes

omit[RW]

@return [Array] the characters to be untouched from the String.

remove[RW]

@return [Array] the characters to be removed from the String.

underscore[RW]

@return [Array] the characters to be transformed into underscores.

Public Class Methods

new() click to toggle source

Creates an instance of the Translations class.

Sets the class variables to a default state.

# File lib/simple_symbolize/translations.rb, line 15
def initialize
  @underscore = [' ']
  @remove = %w[\' ( ) , . : "]
  @omit = []
end

Public Instance Methods

to_omit(t) click to toggle source

Removes characters within the String passed from the @remove and @underscore Arrays.

@param t [String] a String object containing characters to be removed.

@return [Array] the Array of characters to be omitted.

@raise [ArgumentError] if the param does not respond to to_s.

# File lib/simple_symbolize/translations.rb, line 60
def to_omit(t)
  raise ArgumentError 'needs to be a String or respond to #to_s' unless t.respond_to?(:to_s)

  @underscore -= t.to_s.chars
  @remove -= t.to_s.chars
  @omit += t.to_s.chars
end
to_remove(t) click to toggle source

Merges the String passed with the @remove Array omitting duplicates. Removes those characters from the @underscore and @omit Arrays to avoid the change being over-written.

@param t [String] a String object containing characters to be removed.

@return [Array] the Array of characters to be removed.

@raise [ArgumentError] if the param does not respond to to_s.

# File lib/simple_symbolize/translations.rb, line 45
def to_remove(t)
  raise ArgumentError 'needs to be a String or respond to #to_s' unless t.respond_to?(:to_s)

  @underscore -= t.to_s.chars
  @omit -= t.to_s.chars
  @remove |= t.to_s.chars
end
to_underscore(t) click to toggle source

Merges the String passed with the @underscore Array omitting duplicates. Removes those characters from the @remove ans @omit Arrays to avoid the change being over-written.

@param t [String] a String object containing characters to be underscored.

@return [Array] the Array of characters to be underscored.

@raise [ArgumentError] if the param does not respond to to_s.

# File lib/simple_symbolize/translations.rb, line 29
def to_underscore(t)
  raise ArgumentError 'needs to be a String or respond to #to_s' unless t.respond_to?(:to_s)

  @remove -= t.to_s.chars
  @omit -= t.to_s.chars
  @underscore |= t.to_s.chars
end