Skip to content

Instantly share code, notes, and snippets.

@hmadison
Created November 30, 2015 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmadison/0061f1503dcbe62850d0 to your computer and use it in GitHub Desktop.
Save hmadison/0061f1503dcbe62850d0 to your computer and use it in GitHub Desktop.
Sunny Mapper Example
require 'rom-mapper'
require 'pp'
data = [
{
departure_lat: 12,
departure_lon: 75,
destination_lat: 15,
destination_lon: 80
}
]
class MyMapper < ROM::Mapper
step do
attribute(:departure, from: [:departure_lat, :departure_lon]) { |lat,lon| {lat: lat, lon: lon} }
attribute(:destination, from: [:destination_lat, :destination_lon]) { |lat,lon| {lat: lat, lon: lon} }
end
step do
attribute(:locations, from: [:departure, :destination]) { |v1, v2| [v1, v2] }
end
end
pp MyMapper.build.call(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment