Inflect
The micro-framework for service integration.
Overview
Installation
Add this line to your application's Gemfile:
gem 'inflect'
And then execute:
$ bundle
Or install it yourself as:
$ gem install inflect
Usage
Generate your Service:
$ inflect generate:service Weather
IMPORTANT: service name must be in CamelCase.
All the actions that you declare in the array must have its corresponding method.
class WeatherService < Inflect::AbstractService
def initialize
@priority = 2
@words = %W[WEATHER TODAY]
end
# This method will be executed whenever the action is not defined in the
# words query array.
def default
respond "This is the default weather cast"
end
# This is method will be called when the action TODAY is present in
# the words query array. It can optionally carry necessary arguments.
def today(location = nil)
if location.nil?
respond "Weather for today is... very hot."
else
respond "The weather for #{location} is... also very hot."
end
end
end
Call Inflect with the array of words.
words = %W[WEATHER TODAY]
Inflect.handle(words) # Return Response object with weather for today
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/inflect. We follow the Ruby best practices and community-driven standards well explained in bbatsov's ruby-style-guide, see https://github.com/bbatsov/ruby-style-guide.
Docs
To generate docs run (if not installed):
gem install yard
Then to generate the docs:
$ yardoc
To run doc server:
$ yard server
License
The gem is available as open source under the terms of the MIT License.