Class: MultiConverter

Inherits:
Converter show all
Defined in:
lib/puer/converters.rb

Overview

MultiConverter is used for cases when a property in the xhib file’s property bag needs multiple properties in JS Example: => “{123, 456”} should give => 123, :bottom => 456 Done by: MultiConverter.new([:top, :bottom], /(d+)/) {|v| v.to_i}

Instance Method Summary collapse

Constructor Details

#initialize(outputs, regex, &conversion) ⇒ MultiConverter

Returns a new instance of MultiConverter.



25
26
27
28
29
# File 'lib/puer/converters.rb', line 25

def initialize(outputs, regex, &conversion)
  @outputs = outputs
  @regex = regex
  @conversion = conversion || proc {|v| v}
end

Instance Method Details

#props_for(value) ⇒ Object



31
32
33
34
35
# File 'lib/puer/converters.rb', line 31

def props_for(value)
  if match = @regex.match(value)
    Hash[@outputs.zip(match.captures.map(&@conversion))]
  end
end