Class: Accessibility::Translator
- Inherits:
- 
      Object
      
        - Object
- Accessibility::Translator
 
- Defined in:
- lib/accessibility/translator.rb
Overview
Maintain all the rules for transforming Cocoa constants into something a little more Rubyish and taking the Rubyish symbols and translating them back to Cocoa constants.
Class Method Summary collapse
- 
  
    
      .instance  ⇒ Accessibility::Translator 
    
    
  
  
  
  
  
  
  
  
  
    Get the singleton instance of the Translator class. 
Instance Method Summary collapse
- 
  
    
      #classify(klass)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Get the class name equivalent for a given symbol or string. 
- 
  
    
      #cocoaify(key)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Given a symbol, return the equivalent accessibility constant. 
- 
  
    
      #guess_notification(name)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Try to turn an arbitrary symbol into a notification constant, and then get the value of the constant. 
- 
  
    
      #initialize  ⇒ Translator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Initialize the caches. 
- 
  
    
      #rubyize(keys)  ⇒ Array<Symbol> 
    
    
  
  
  
  
  
  
  
  
  
    Take an array of Cocoa accessibility constants and return an array of shortened Ruby symbols. 
- 
  
    
      #singularize(klass)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Get the singularized version of the word passed in. 
- 
  
    
      #unprefix(key)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Takes an accessibility constant and returns a new string with the namespace prefix removed. 
Constructor Details
#initialize ⇒ Translator
Initialize the caches.
| 31 32 33 34 35 36 37 | # File 'lib/accessibility/translator.rb', line 31 def initialize init_unprefixes init_rubyisms init_cocoaifications init_classifications init_singularizations end | 
Class Method Details
.instance ⇒ Accessibility::Translator
Get the singleton instance of the Accessibility::Translator class.
This is meant to mimic the important functionality of the
Singleton mix-in.
| 25 26 27 | # File 'lib/accessibility/translator.rb', line 25 def self.instance @instance ||= new end | 
Instance Method Details
#classify(klass) ⇒ String
Get the class name equivalent for a given symbol or string. This
is just a caching front end to the #classify method from the
ActiveSupport inflector.
| 97 98 99 | # File 'lib/accessibility/translator.rb', line 97 def classify klass @classifications[klass] end | 
#cocoaify(key) ⇒ String
Given a symbol, return the equivalent accessibility constant.
| 81 82 83 | # File 'lib/accessibility/translator.rb', line 81 def cocoaify key @cocoaifications[key.to_sym] end | 
#guess_notification(name) ⇒ String
Try to turn an arbitrary symbol into a notification constant, and then get the value of the constant. If it cannot be turned into a notification constant then the original string parameter will be returned.
| 125 126 127 128 129 | # File 'lib/accessibility/translator.rb', line 125 def guess_notification name name = name.to_s.gsub(/(?:^|_)(.)/) do $1.upcase! || $1 end const = "KAX#{name}Notification" Object.const_defined?(const) ? Object.const_get(const) : name end | 
#rubyize(keys) ⇒ Array<Symbol>
Take an array of Cocoa accessibility constants and return an array of shortened Ruby symbols.
| 70 71 72 73 74 | # File 'lib/accessibility/translator.rb', line 70 def rubyize keys keys = keys.map { |x| @rubyisms[x] } keys.flatten! keys end | 
#singularize(klass) ⇒ String
Get the singularized version of the word passed in. This is just
a caching front end to the #singularize method from the
ActiveSupport inflector.
| 113 114 115 | # File 'lib/accessibility/translator.rb', line 113 def singularize klass @singularizations[klass] end | 
#unprefix(key) ⇒ String
In the case of a predicate name, this will strip the 'Is' part of the name if it is present
Takes an accessibility constant and returns a new string with the namespace prefix removed.
| 56 57 58 | # File 'lib/accessibility/translator.rb', line 56 def unprefix key @unprefixes[key] end |