Project

sorta-lens

0.0
No release in over a year
Simple lensing for your data extraction needs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Sorta-lens Gem Version Ruby

Simple lensing for your data extraction needs

Installation

Add it to your gemfile:

gem 'sorta-lens', '~> 0.1.0'

or install globally for use in scripts or IRB

gem install sorta-lens

Usage

Simply instantiate a Lens and start applying it to your objects:

  complex1 = { id: 451, .... status: :active }
  complex2 = User.first # has property `id` and method `status`
  lens = Sorta::Lens.on :id, :status
  lens.(complex1) # => { id: 451, status: :active }
  lens.(complex2) # => { id: 1, status: :online }

There is also a typed version:

  complex1 = { id: 451, .... status: :active }
  complex2 = { id: 9001, .... status: "online" }
  lens = Sorta::Lens.typed.on id: Integer, status: String
  lens.(complex1) # => TypedLens::TypeError (Unexpected type. Expected String got Symbol)
  lens.(complex2) # => { id: 9001, status: "online" }