Class: Linguistics::Inflector
- Inherits:
-
Object
- Object
- Linguistics::Inflector
- Extended by:
- Loggability
- Defined in:
- lib/linguistics/inflector.rb
Overview
A facade object that acts as the extension point for linguistic modules for a single language. A single instance of an inflector is generated for an object that has been extended with a Linguistics language the first time the language is used.
Instance Attribute Summary collapse
-
#language_code ⇒ Object
readonly
The inflector’s language code.
-
#obj ⇒ Object
readonly
The object the inflector is delegating for.
Instance Method Summary collapse
-
#initialize(language_code, obj) ⇒ Inflector
constructor
Create a new inflector for
obj
. -
#inspect ⇒ Object
Output a programmer-readable representation of the object suitable for debugging.
-
#language ⇒ Object
Return the english-language name of the language the inflector is delegating for.
-
#respond_to_missing?(message, include_priv = false) ⇒ Boolean
Returns
true
if either the inflector or the object it’s wrapping respond to the specifiedmessage
. -
#to_i ⇒ Object
Return the target object as an Integer.
-
#to_s ⇒ Object
Return the target object as a String.
Constructor Details
#initialize(language_code, obj) ⇒ Inflector
Create a new inflector for obj
.
20 21 22 23 24 25 26 |
# File 'lib/linguistics/inflector.rb', line 20 def initialize( language_code, obj ) raise TypeError, "can't inflect for another inflector!" if obj.is_a?( Linguistics::Inflector ) @language_code = language_code @obj = obj super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (protected)
Delegate missing methods to the target object.
81 82 83 84 85 86 |
# File 'lib/linguistics/inflector.rb', line 81 def method_missing( sym, *args, &block ) return super unless self.obj.respond_to?( sym ) meth = self.obj.method( sym ) self.singleton_class.send( :define_method, sym, &meth ) return self.method( sym ).call( *args, &block ) end |
Instance Attribute Details
#language_code ⇒ Object (readonly)
The inflector’s language code
37 38 39 |
# File 'lib/linguistics/inflector.rb', line 37 def language_code @language_code end |
#obj ⇒ Object (readonly)
The object the inflector is delegating for
34 35 36 |
# File 'lib/linguistics/inflector.rb', line 34 def obj @obj end |
Instance Method Details
#inspect ⇒ Object
Output a programmer-readable representation of the object suitable for debugging.
67 68 69 70 71 72 73 |
# File 'lib/linguistics/inflector.rb', line 67 def inspect return "#<(%s-language inflector) for <%s:0x%0x> >" % [ self.language, @obj.class, @obj.object_id / 2 ] end |
#language ⇒ Object
Return the english-language name of the language the inflector is delegating for.
42 43 44 |
# File 'lib/linguistics/inflector.rb', line 42 def language ::Linguistics::ISO639::LANGUAGE_CODES[ self.language_code.to_sym ][:eng_name] end |
#respond_to_missing?(message, include_priv = false) ⇒ Boolean
Returns true
if either the inflector or the object it’s wrapping respond to the specified message
.
49 50 51 |
# File 'lib/linguistics/inflector.rb', line 49 def respond_to_missing?( , include_priv=false ) return self.obj.respond_to?( , include_priv ) end |
#to_i ⇒ Object
Return the target object as an Integer
61 62 63 |
# File 'lib/linguistics/inflector.rb', line 61 def to_i return self.obj.to_i end |
#to_s ⇒ Object
Return the target object as a String.
55 56 57 |
# File 'lib/linguistics/inflector.rb', line 55 def to_s return self.obj.to_s end |