Sha256: 95e1f384ca410d88db01e331294cec6b72de85a41b4350d96812049acadbbfbe

Contents?: true

Size: 679 Bytes

Versions: 6

Compression:

Stored size: 679 Bytes

Contents

module Rake::Funnel::Support::MapperStyles
  class Default
    attr_reader :prefix, :value_separator

    def initialize
      @prefix = '/'
      @value_separator = ','
    end

    def generate_from(model)
      model.map { |switch|
        switch.values.flatten.map { |value|
          [top_level(switch), nested(value)].reject(&:empty?)
        }
      }.flatten(2)
    end

    private
    def top_level(switch)
      [prefix, switch.switch]
    end

    def nested(value)
      res = []
      res << value.key
      res << value_separator unless value.key.nil? || value.value.nil?
      res << value.value
      res.compact
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rake-funnel-0.0.6.pre lib/rake/funnel/support/mapper_styles/default.rb
rake-funnel-0.0.5.pre lib/rake/funnel/support/mapper_styles/default.rb
rake-funnel-0.0.4.pre lib/rake/funnel/support/mapper_styles/default.rb
rake-funnel-0.0.3.pre lib/rake/funnel/support/mapper_styles/default.rb
rake-funnel-0.0.2.pre lib/rake/funnel/support/mapper_styles/default.rb
rake-funnel-0.0.1.pre lib/rake/funnel/support/mapper_styles/default.rb