Class: SimpleSymbolize::Translations

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_symbolize/translations.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTranslations

Creates an instance of the Translations class.

Sets the class variables to a default state.



19
20
21
# File 'lib/simple_symbolize/translations.rb', line 19

def initialize
  reset!
end

Instance Attribute Details

#handle_camel_caseObject

Returns the value of attribute handle_camel_case.



14
15
16
# File 'lib/simple_symbolize/translations.rb', line 14

def handle_camel_case
  @handle_camel_case
end

#omitArray (readonly)

Returns the characters to be untouched from the String.

Returns:

  • (Array)

    the characters to be untouched from the String.



12
13
14
# File 'lib/simple_symbolize/translations.rb', line 12

def omit
  @omit
end

#removeArray (readonly)

Returns the characters to be removed from the String.

Returns:

  • (Array)

    the characters to be removed from the String.



10
11
12
# File 'lib/simple_symbolize/translations.rb', line 10

def remove
  @remove
end

#underscoreArray (readonly)

Returns the characters to be transformed into underscores.

Returns:

  • (Array)

    the characters to be transformed into underscores.



8
9
10
# File 'lib/simple_symbolize/translations.rb', line 8

def underscore
  @underscore
end

Instance Method Details

#reset!Object



71
72
73
74
75
76
# File 'lib/simple_symbolize/translations.rb', line 71

def reset!
  @underscore = [' ', '::', '-']
  @remove = %w[' ( ) , . : " ! @ £ $ % ^ & * / { } [ ] < > ; = #]
  @omit = []
  @handle_camel_case = true
end

#to_omit=(chars) ⇒ Array

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

Parameters:

  • chars (String)

    a String object containing characters to be removed.

Returns:

  • (Array)

    the Array of characters to be omitted.



56
57
58
59
60
61
62
# File 'lib/simple_symbolize/translations.rb', line 56

def to_omit=(chars)
  chars = sanitise_chars(chars)

  @underscore -= chars
  @remove -= chars
  @omit += chars
end

#to_remove=(chars) ⇒ Array

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.

Parameters:

  • chars (String)

    a String object containing characters to be removed.

Returns:

  • (Array)

    the Array of characters to be removed.



43
44
45
46
47
48
49
# File 'lib/simple_symbolize/translations.rb', line 43

def to_remove=(chars)
  chars = sanitise_chars(chars)

  @underscore -= chars
  @omit -= chars
  @remove |= chars
end

#to_underscore=(chars) ⇒ Array

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

Parameters:

  • chars (Array)

    an object containing characters to be underscored.

Returns:

  • (Array)

    the Array of characters to be underscored.



29
30
31
32
33
34
35
# File 'lib/simple_symbolize/translations.rb', line 29

def to_underscore=(chars)
  chars = sanitise_chars(chars)

  @remove -= chars
  @omit -= chars
  @underscore |= chars
end