Module: Iteraptor
- Defined in:
- lib/iteraptor.rb,
lib/iteraptor/greedy.rb,
lib/iteraptor/version.rb
Overview
rubocop:disable Style/VariableNumber rubocop:disable Metrics/ModuleLength
Constant Summary collapse
- DELIMITER =
'.'.freeze
- VERSION =
'0.6.0'
Class Method Summary collapse
Instance Method Summary collapse
-
#aplanar(**params) ⇒ Object
rubocop:enable Style/Alias.
- #escoger(*filter, **params, &λ) ⇒ Object (also: #segar)
- #plana_mapa(**params) ⇒ Object
- #rechazar(*filter, **params, &λ) ⇒ Object
- #recoger(**params) ⇒ Object
Class Method Details
.attach_to(klazz) ⇒ Object
2 3 4 |
# File 'lib/iteraptor/greedy.rb', line 2 def attach_to klazz klazz.send :include, Iteraptor end |
.included(base) ⇒ Object
8 9 10 |
# File 'lib/iteraptor.rb', line 8 def self.included base raise "This module might be included into Enumerables only" unless base.ancestors.include? Enumerable end |
Instance Method Details
#aplanar(**params) ⇒ Object
rubocop:enable Style/Alias
36 37 38 39 40 41 42 43 44 |
# File 'lib/iteraptor.rb', line 36 def aplanar **params return self if empty? cada(**params).with_object({}) do |(key, value), acc| key = key.join(iteraptor_delimiter(params)) if params[:full_parent] key = key.to_sym if params[:symbolize_keys] acc[key] = value unless value.is_a?(Enumerable) yield key, value if block_given? end end |
#escoger(*filter, **params, &λ) ⇒ Object Also known as: segar
27 28 29 30 |
# File 'lib/iteraptor.rb', line 27 def escoger *filter, **params, & |
#plana_mapa(**params) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/iteraptor.rb', line 61 def plana_mapa **params return enum_for(:plana_mapa, delimiter: params[:delimiter], **params) unless block_given? return self if empty? cada(**params).with_object([]) do |(key, value), acc| key = key.join(iteraptor_delimiter(params)) if params[:full_parent] key = key.to_sym if params[:symbolize_keys] acc << yield(key, value) unless value.is_a?(Enumerable) end end |
#rechazar(*filter, **params, &λ) ⇒ Object
22 23 24 25 |
# File 'lib/iteraptor.rb', line 22 def rechazar *filter, **params, & |
#recoger(**params) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/iteraptor.rb', line 46 def recoger **params return self if empty? # rubocop:disable Style/MultilineBlockChain aplanar(**params).each_with_object( Hash.new { |h, k| h[k] = h.clone.clear } ) do |(k, v), acc| keys = k.to_s.split(iteraptor_delimiter(params)) parent = keys[0..-2].reduce(acc){ |h, kk| h[kk] } parent[keys.last] = v end.mapa(yield_all: true, **params) do |_parent, (k, v)| [k, v] end # rubocop:enable Style/MultilineBlockChain end |