Class: Intercept::Strategy::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/intercept/strategy/mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_map, fallback_strategy = nil) ⇒ Mapper



8
9
10
11
# File 'lib/intercept/strategy/mapper.rb', line 8

def initialize(bucket_map, fallback_strategy = nil)
  @bucket_map = parse_bucket_map bucket_map
  @fallback_strategy = fallback_strategy
end

Instance Attribute Details

#bucket_mapObject (readonly)

Returns the value of attribute bucket_map.



6
7
8
# File 'lib/intercept/strategy/mapper.rb', line 6

def bucket_map
  @bucket_map
end

#fallback_strategyObject (readonly)

Returns the value of attribute fallback_strategy.



6
7
8
# File 'lib/intercept/strategy/mapper.rb', line 6

def fallback_strategy
  @fallback_strategy
end

Instance Method Details

#process(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/intercept/strategy/mapper.rb', line 13

def process(value)
  return value if value.nil? || value.empty?

  mapped_value = map_value(value)

  if fallback_strategy && mapped_value.empty?
    fallback_strategy.process(value)
  else
    mapped_value
  end
end