RubyGems Navigation menu

to_collection 1.0.0

Treat an array of objects and a singular object uniformly as a collection of objects. Especially useful in processing REST Web Service API JSON responses in a functional approach. Canonicalize data to treat uniformly whether it comes in as a single object or an array of objects, dropping `nils` out automatically. API: `object.to_collection(compact)` where `compact` is a boolean for whether to compact collection or not. It is true by default. Example: ```ruby city_counts = {} people_http_request.to_collection.each do |person| city_counts[person["city"]] ||= 0 city_counts[person["city"]] += 1 end ``` Wanna keep `nil` values? No problem! Just pass `false` as an argument: ```ruby bad_people_count = 0 city_counts = {} people_http_request.to_collection(false).each do |person| if person.nil? bad_people_count += 1 else city_counts[person["city"]] ||= 0 city_counts[person["city"]] += 1 end end ```

バージョン履歴:

  1. 2.0.1 - December 09, 2020 (9.5KB)
  2. 2.0.0 - May 29, 2020 (8.5KB)
  3. 1.0.1 - August 06, 2019 (9.5KB)
  4. 1.0.0 - February 22, 2017 (9.5KB)

Runtime依存性 (1):

super_module = 1.2.0

Development依存性 (3):

coveralls ~> 0.8.19
jeweler ~> 2.3.3
rspec ~> 3.5.0

オーナー:

作者:

  • Andy Maleh

SHA 256チェックサム:

d04afc14d1c61d2ba6c7b9fbc3ca800b92f7b468f9190850162d8752d52809f4

累計ダウンロード数 6,374

このバージョンのみ 1,845

Gemfile:
= クリップボードにコピー コピー完了!

インストール:
=

ライセンス:

MIT

必要Rubyバージョン: >= 0

リンク: