Skip to content

Commit cc4c128

Browse files
committed
Update README with basic instructions
Ticket: https://trello.com/c/oN9w1d9g
1 parent adcdd18 commit cc4c128

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

README.md

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# OrderTransformer
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/data_transformer`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
Note: This gem is in maintenance mode and not actively updated.
44

5-
TODO: Delete this and the text above, and describe your gem
5+
The order transformer transforms data from an external format to the desired target format.
66

77
## Installation
88

@@ -12,18 +12,64 @@ Add this line to your application's Gemfile:
1212
gem 'order_transformer'
1313
```
1414

15-
And then execute:
15+
And then run `bundle install`.
1616

17-
$ bundle install
17+
## Usage
1818

19-
Or install it yourself as:
19+
The gem allows you to define data transformations via a DSL like so:
2020

21-
$ gem install data_transformer
21+
```ruby
22+
OrderTransformer::DSL.define :some_shop, "v1.0" do
23+
definition do
24+
order as: :hash do
25+
# The core of the transformation process is implemented by using the `transform` method. This maps the input "OrderNumber" field to the output "order_number" field.
26+
transform "OrderNumber", to: "_order_number"
27+
28+
# By default, values of input data are not required to be set. To
29+
# require them, set `optional: false`:
30+
transform "OrderNumber", to: "_order_number", optional: false
31+
32+
# If you need to modify the input data, provide a custom transform instruction:
33+
transform "OrderNumber", to: "_order_number", transformer: ->(order_number) { order_number.to_d }
34+
35+
# The gem also comes with some default transformers that are always included.
36+
# See `DefaultTransformers`.
37+
# The above can be rewritten as:
38+
transform "OrderNumber", to: "_order_number", transformer: to_d
39+
40+
# Using multiple inputs is also possible:
41+
transform "street_1", "street_2", "street_3", to: "_order_number", transformer: ->(street_1, street_2, street_3) { street_1 || street_2 || street_3 }
42+
43+
end
44+
end
45+
end
46+
```
2247

23-
## Usage
48+
You can collect your own data transformers in a plain Ruby module:
49+
50+
```ruby
51+
module MyTransformers
52+
def presence(chain = nil)
53+
chain ||= __create_method_chain(caller(1, 1))
54+
chain.add ->(value, *_args) { value.presence }
55+
end
56+
end
57+
```
2458

25-
TODO: Write usage instructions here
59+
and include it in your transformer:
2660

61+
62+
```ruby
63+
OrderTransformer::DSL.define :some_shop, "v1.0" do
64+
include_transformers MyTransformers
65+
66+
definition do
67+
order as: :hash do
68+
transform "OrderNumber", to: "_order_number", transformer: presence
69+
end
70+
end
71+
end
72+
```
2773
## Development
2874

2975
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -50,9 +96,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
5096
- create branch from master
5197
- bump version to next pre `be gem bump -v pre --pretend` and after check `be gem bump -v pre`
5298
- merge branch (merge commit!) into development
53-
54-
## Contributing
55-
56-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/data_transformer.
57-
58-

0 commit comments

Comments
 (0)