Class: Isomorphic::Inflector::AbstractInflector Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorphic/inflector.rb

Overview

This class is abstract.

Generic base class for Isomorphic inflectors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ AbstractInflector

Default constructor

Parameters:

  • base (Module)

    the base module



79
80
81
82
83
# File 'lib/isomorphic/inflector.rb', line 79

def initialize(base)
  super()

  @base = base
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



74
75
76
# File 'lib/isomorphic/inflector.rb', line 74

def base
  @base
end

Instance Method Details

#convert_hash(constructor = {}) ⇒ Isomorphic::HashWithIndifferentAccess

Inflect upon the given hash or constructor for a hash.

Parameters:

  • constructor (Hash, #to_hash) (defaults to: {})

    the hash or constructor for a hash

Returns:

Raises:



90
91
92
# File 'lib/isomorphic/inflector.rb', line 90

def convert_hash(constructor = {})
  Isomorphic::HashWithIndifferentAccess.new(self, constructor)
end

#isomorphism(terms) ⇒ String

Inflect upon the given terms.

Examples:

Inflect upon a String

Isomorphic::Inflector.new(Foo).isomorphism("bar") #=> "foo_bar"

Inflect upon a Symbol

Isomorphic::Inflector.new(Foo).isomorphism(:bar) #=> "foo_bar"

Inflect upon a Class

Isomorphic::Inflector.new(Foo).isomorphism(Foo::Bar) #=> "foo_bar"

Inflect upon an Array of inflectable terms

Isomorphic::Inflector.new(Foo).isomorphism(["bar", "fum", "baz"]) #=> "foo_bar_and_foo_fum_and_foo_baz"

Inflect upon an inflectable term-alias pair

Isomorphic::Inflector.new(Foo).isomorphism([["bar", "ex1"]]) #=> "foo_bar_as_ex1"

Inflect upon an Array of inflectable term-alias pairs

Isomorphic::Inflector.new(Foo).isomorphism([["bar", "ex1"], ["bar", "ex2"], ["bar", "ex3"]]) #=> "foo_bar_as_ex1_and_foo_bar_as_ex2_and_foo_bar_as_ex3"

Parameters:

  • terms (Array<Object>)

    the inflectable terms

Returns:

  • (String)

    the inflection

Raises:



112
113
114
# File 'lib/isomorphic/inflector.rb', line 112

def isomorphism(terms)
  isomorphism_for(terms)
end