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
-
#handle_camel_case ⇒ Object
Returns the value of attribute handle_camel_case.
-
#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=(chars) ⇒ Array
Removes characters within the String passed from the @remove and @underscore Arrays.
-
#to_remove=(chars) ⇒ Array
Merges the String passed with the @remove Array omitting duplicates.
-
#to_underscore=(chars) ⇒ 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.
19 20 21 |
# File 'lib/simple_symbolize/translations.rb', line 19 def initialize reset! end |
Instance Attribute Details
#handle_camel_case ⇒ Object
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 |
#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
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.
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.
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.
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 |