Module: Ucb

Defined in:
lib/ucb/hcm/data_fetcher.rb,
lib/ucb/hcm.rb,
lib/ucb/hcm/api.rb,
lib/ucb/hcm/client.rb,
lib/ucb/hcm/request.rb,
lib/ucb/hcm/version.rb,
lib/ucb/hcm/response.rb,
lib/ucb/hcm/configuration.rb

Overview

This is a utility class that makes it easy to grab deeply nested values safely. Given a Hash like: fetcher = DataFetcher.new(

 {
   "names"=>[{
     "type"=>{"code"=>"PRI", "description"=>"Primary"},
     "familyName"=>"Montalban",
     "givenName"=>"Ricardo",
   }],
 }
)

you could access the name code like this:

fetcher.names.first.type.code.value

If any part of the path is missing or nil, no exception will be raised, and the value() call will return nil.

By default, you’ll get nil back if any part of call chain is missing or nil. If you want a different fallback value, you can pass that to value(). This would return “not found”:

fetcher.thisIsNotInTheResponseHash.first.type.code.value("not found")

DataFetcher will accept node names in camel case or snake case. The following are equivalent:

fetcher.names.first.familyName.value
fetcher.names.first.family_name.value

Defined Under Namespace

Modules: Hcm