Sha256: d738e88b8fb2ace30a15817fba150cb26950de3de6cfb6672875b87868639c24
Contents?: true
Size: 1.09 KB
Versions: 4
Compression:
Stored size: 1.09 KB
Contents
# Converters converts data in the xib files property bag to the NodeInfos property bag. # The output key it will have is stored here. The converter can be created with a conversion block # Converter.new :output {|v| Convert value v here...} class Converter def initialize(output, &conversion) @output = output @conversion = conversion || proc {|v| v} end def props_for(value) converted_value = @conversion.call(value) if converted_value { @output => converted_value } end end end # MultiConverter is used for cases when a property in the xhib file's property bag needs multiple # properties in JS # Example: {'frameOrigin' => "{123, 456}"} should give {:top => 123, :bottom => 456} # Done by: MultiConverter.new([:top, :bottom], /\{(\d+), (\d+)\}/) {|v| v.to_i} class MultiConverter < Converter def initialize(outputs, regex, &conversion) @outputs = outputs @regex = regex @conversion = conversion || proc {|v| v} end def props_for(value) if match = @regex.match(value) Hash[@outputs.zip(match.captures.map(&@conversion))] end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
puer-0.0.6 | lib/puer/converters.rb |
puer-0.0.4 | lib/puer/converters.rb |
puer-0.0.3 | lib/puer/converters.rb |
puer-0.0.2 | lib/puer/converters.rb |