πŸ“¦ amarshall / windcharger

A small library to easily make objects that transform input via many methods.

β˜… 1 stars β‘‚ 0 forks πŸ‘ 1 watching βš–οΈ MIT License
πŸ“₯ Clone https://github.com/amarshall/windcharger.git
HTTPS git clone https://github.com/amarshall/windcharger.git
SSH git clone git@github.com:amarshall/windcharger.git
CLI gh repo clone amarshall/windcharger
Andrew Marshall Andrew Marshall v0.7.0 1e0af74 2 years ago πŸ“ History
πŸ“‚ master View all commits β†’
πŸ“ .github
πŸ“ lib
πŸ“ spec
πŸ“„ .gitignore
πŸ“„ Gemfile
πŸ“„ LICENSE.txt
πŸ“„ Rakefile
πŸ“„ README.md
πŸ“„ README.md

Windcharger

Gem Version

Windcharger mascot. He carries powerful magnets in his arms that he can use to manipulate large objects.

Windcharger is a small library to easily make objects that transform input via many methods.

Installation

Install as usual: gem install windcharger or add gem 'windcharger' to your Gemfile.

Usage

Declare methods as attributes by extending Windcharger::Attributes and preceding methods with attribute:

require 'windcharger'

class MyTransformer
  extend Windcharger::Attributes

  attribute
  def foo; end

  attribute
  def bar; end

  def not_an_attribute; end
end

MyTransformer.attributes  #=> [:foo, :bar]

This isn’t very useful on its own, so include Windcharger::HashTransformer to get the transform method:

require 'windcharger'

class MyTransformer
  extend Windcharger::Attributes
  include Windcharger::HashTransformer

  attribute
  def foo
    :the_foo
  end

  attribute
  def bar
    :walked_into_a_bar
  end

  def qux
    1
  end

  attribute :qax, :qux

  def qax
    2
  end

  def not_an_attribute
    42
  end
end

my_transformer = MyTransformer.new
my_transformer.transform
#=> {
#     :foo => :the_foo,
#     :bar => :walked_into_a_bar,
#     :qax => 2,
#     :qux => 1,
#   }

Add an initialize that takes some input and then transform it to each attribute in their respective methods and you have a nice transformer object.

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Credits & License

Copyright Β© 2013–Present J. Andrew Marshall. License is available in the LICENSE file.