0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A doc converter to another doc. Doc is a data structure like a hash, array or a simple string
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.2
>= 0
 Project Readme

DocWrapper¶ ↑

This project rocks and uses MIT-LICENSE.

Description¶ ↑

Doc wrapper, convert a doc in another doc. Doc is some ruby data structure, like a Hash, Array or a simple String

The advantage is that the conversion engine is automatically identified, making the code cleaner

Example¶ ↑
:001 > DocWrapper.to_target_doc {origin: :sales, user_id: 1, account_id: 99 }   
=>  { user: 'John', account_name: 'xxxx' }

another example, only changes de origin key
  :002 > DocWrapper.to_target_doc {owner: :billing, user_id: 1, account_id: 99 }
  ==> { user_name: 'john', amount: 100.87 }

Install¶ ↑

$ gem install ds_doc_wrapper

Usage¶ ↑

First you need define some doc wrappers

class DocWrapper::DocByTomCat
  def self.to_target_doc a_doc
    # --  here put you converter code
    {
      cat_name: a_doc['name'],
      cat_eat: a_doc['food']
    }
  end
end

another doc wrapper:

class DocWrapper::DocByCook
  def self.to_target_doc a_doc
    # --  here put you converter code
    {
      name: a_doc['name'],
      main: "#{a_doc['food']} dinner"
    }
  end
end

them:
  :003 > DocWrapper::Base.to_target_doc( { owner: 'tom_cat', 'name' => 'Tom', 'food' => 'fish' } )
  ==> { cat_name: 'Tom', cat_eat: 'fish' }

  :004 >  DocWrapper::Base.to_target_doc( { owner: 'cook', 'name' => 'Tom', 'food' => 'fish' } )
  ==> { name: 'Tom', main: 'fish dinner' }

Change log ¶ ↑

  • 1.2 -> Add ds_hash dependency

  • 1.1 -> Add default options configurations