Class: SimpleSymbolize::Translations
- Inherits:
-
Object
- Object
- SimpleSymbolize::Translations
- 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
-
#camel_case_acronyms ⇒ Array
The characters to be transformed into uppercase during camelisation.
-
#handle_camel_case ⇒ Boolean
Whether to handle camelCase strings during symbolisation.
-
#omit ⇒ Array
readonly
The characters to be untouched from the String.
-
#remove ⇒ Array
readonly
The characters to be removed from the String.
-
#underscore ⇒ Array
readonly
The characters to be transformed into underscores.
Instance Method Summary collapse
-
#initialize ⇒ Translations
constructor
Creates an instance of the Translations class.
- #reset! ⇒ Object
-
#to_omit=(input) ⇒ Array
Removes characters within the String passed from @remove and @underscore Arrays.
-
#to_remove=(input) ⇒ Array
Merges the String passed with the @remove Array omitting duplicates.
-
#to_underscore=(input) ⇒ Array
Merges the String passed with the @underscore Array omitting duplicates.
Constructor Details
#initialize ⇒ Translations
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_acronyms ⇒ Array
Returns 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_case ⇒ Boolean
Returns 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 |
#omit ⇒ Array (readonly)
Returns the characters to be untouched from the String.
12 13 14 |
# File 'lib/simple_symbolize/translations.rb', line 12 def omit @omit end |
#remove ⇒ Array (readonly)
Returns the characters to be removed from the String.
10 11 12 |
# File 'lib/simple_symbolize/translations.rb', line 10 def remove @remove end |
#underscore ⇒ Array (readonly)
Returns 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.
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.
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.
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 |