Skip to content

Commit

Permalink
Om Sree Ganeshaya Namah: The first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
parolkar committed Apr 1, 2009
0 parents commit 8fa2975
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2009 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 36 additions & 0 deletions README
@@ -0,0 +1,36 @@
Inflectionist
=============

The old school ActiveSupport's inflections allowed you to pluralize, singularize , humanize etc. And when you wanted little more complex linguistic processing , you found nothing. Here comes Inflectionist for your rescue. It is an extension to ActiveSupport inflections available in form of a rails plugin. For now, this will allow you to find simple past tense of any given word.



Example
=======

"create".past_tensed => "created"
"buy".past_tensed => "baught"
"fight".past_tensed => "faught"
"market".past_tensed => "marketed"
"animate".past_tensed => "animated"
"fluctuate".past_tensed => "fluctuated"
"tag".past_tensed => "tagged"
"feel".past_tensed => "felt"


Installation
============

...



Goals & TODO
============
1.) Implement past to present tense conversion
2.) Implement more complex linguistic processing
3.) Add more inflections



Copyright (c) 2009 Er Abhishek Parolkar, released under the MIT license
23 changes: 23 additions & 0 deletions Rakefile
@@ -0,0 +1,23 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the inflectionist plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the inflectionist plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Inflectionist'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
6 changes: 6 additions & 0 deletions init.rb
@@ -0,0 +1,6 @@
# Author: Er Abhishek Parolkar

require File.dirname(__FILE__) + '/lib/inflectionist'
require File.dirname(__FILE__) + '/lib/inflections'
require File.dirname(__FILE__) + '/lib/string_ext'
ActiveSupport::Inflector.send(:extend, ParolkarInnovationLab::Inflectionist)
1 change: 1 addition & 0 deletions install.rb
@@ -0,0 +1 @@
# Install hook code here
39 changes: 39 additions & 0 deletions lib/inflectionist.rb
@@ -0,0 +1,39 @@
#Copyright (c) 2009 Er Abhishek Parolkar, released under the MIT license
module ParolkarInnovationLab
module Inflectionist

def past_tensed(word)
result = word.to_s.dup

if word.empty? || inflections.uncountables.include?(result.downcase)
result
else
inflections.past_tenses.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result
end
end
end
end



ActiveSupport::Inflector::Inflections.instance.instance_eval do # Keep in mind Inflections is a singleton, so what makes more sense is to inject our methods at run time to the instance

def past_tenses # a attr_reader
@past_tenses
end
def past_tense(rule, replacement)
@past_tenses = [] if !@past_tenses
@uncountables.delete(rule) if rule.is_a?(String)
@uncountables.delete(replacement)
@past_tenses.insert(0, [rule, replacement])
end

end







20 changes: 20 additions & 0 deletions lib/inflections.rb
@@ -0,0 +1,20 @@
# this is where we define all the inflections for functionalities added by inflectionist plugin

ActiveSupport::Inflector.inflections do |inflect|
inflect.past_tense /^(.*)$/,'\1ed'
inflect.past_tense /e$/,'ed'
inflect.past_tense /t$/,'ted'
inflect.past_tense /g$/,'gged'
inflect.past_tense /ight$/,'aught'
inflect.past_tense "buy",'baught'
inflect.past_tense "sell",'sold'
inflect.past_tense "is",'was'
inflect.past_tense "are",'were'
inflect.past_tense "teach",'taught'
inflect.past_tense "feel",'felt'





end
21 changes: 21 additions & 0 deletions lib/string_ext.rb
@@ -0,0 +1,21 @@


# in case active_support/inflector is required without the rest of active_support
require 'active_support/inflections'
require 'active_support/core_ext/string/inflections'
require 'active_support/inflector' unless defined?(ActiveSupport::Inflector)

module ActiveSupport
module CoreExtensions
module String #:nodoc:
module Inflections
def past_tensed
Inflector.past_tensed(self)
end
end
end
end
end

String.send :include, ActiveSupport::CoreExtensions::String::Inflections # this is required for above changes to take effect

4 changes: 4 additions & 0 deletions tasks/inflectionist_tasks.rake
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :inflectionist do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/inflectionist_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class InflectionistTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
1 change: 1 addition & 0 deletions uninstall.rb
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit 8fa2975

Please sign in to comment.