Inflector

class
Superclass
Object
Extended With
Loggability

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.

Attributes

language_code[R]

The inflector's language code

obj[R]

The object the inflector is delegating for

Public Class Methods

anchor
new( language_code, obj )

Create a new inflector for obj.

# File lib/linguistics/inflector.rb, line 19
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

Public Instance Methods

anchor
inspect()

Output a programmer-readable representation of the object suitable for debugging.

# File lib/linguistics/inflector.rb, line 66
def inspect
        return "#<(%s-language inflector) for <%s:0x%0x> >" % [
                self.language,
                @obj.class,
                @obj.object_id / 2
        ]
end
anchor
language()

Return the english-language name of the language the inflector is delegating for.

# File lib/linguistics/inflector.rb, line 41
def language
        ::Linguistics::ISO639::LANGUAGE_CODES[ self.language_code.to_sym ][:eng_name]
end
anchor
respond_to_missing?( message, include_priv=false )

Returns true if either the inflector or the object it's wrapping respond to the specified message.

# File lib/linguistics/inflector.rb, line 48
def respond_to_missing?( message, include_priv=false )
        return self.obj.respond_to?( message, include_priv )
end
anchor
to_i()

Return the target object as an Integer

# File lib/linguistics/inflector.rb, line 60
def to_i
        return self.obj.to_i
end
anchor
to_s()

Return the target object as a String.

# File lib/linguistics/inflector.rb, line 54
def to_s
        return self.obj.to_s
end

Protected Instance Methods

anchor
method_missing( sym, *args, &block )

Delegate missing methods to the target object.

# File lib/linguistics/inflector.rb, line 80
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