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.



21
22
23
# File 'lib/simple_symbolize/translations.rb', line 21

def initialize
  reset!
end

Instance Attribute Details

#camel_case_acronymsArray

Returns the characters to be transformed into uppercase during camelisation.

Returns:

  • (Array)

    the characters to be transformed into uppercase during camelisation.



16
17
18
# File 'lib/simple_symbolize/translations.rb', line 16

def camel_case_acronyms
  @camel_case_acronyms
end

#handle_camel_caseBoolean

Returns whether to handle camelCase strings during symbolisation.

Returns:

  • (Boolean)

    whether to handle camelCase strings during symbolisation.



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



79
80
81
82
83
84
85
# File 'lib/simple_symbolize/translations.rb', line 79

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

#to_omit=(input) ⇒ Array

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

Parameters:

  • input (String)

    a String object containing characters to be removed.

Returns:

  • (Array)

    the Array of characters to be omitted.



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

def to_omit=(input)
  arr = sanitise(input)

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

#to_remove=(input) ⇒ Array

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

Parameters:

  • input (String)

    a String object containing characters to be removed.

Returns:

  • (Array)

    the Array of characters to be removed.



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

def to_remove=(input)
  arr = sanitise(input)

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

#to_underscore=(input) ⇒ Array

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

Parameters:

  • input (Array)

    an object containing characters to be underscored.

Returns:

  • (Array)

    the Array of characters to be underscored.



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

def to_underscore=(input)
  arr = sanitise(input)

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