Sha256: 1075f14cd6b6129118165589bc46bf5b69d8a2330b15a2bcbcfd09e281fe5352

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

require 'yaml'

module Spout
  module Helpers
    class ConfigReader

      attr_reader :slug, :visit, :charts, :webservers

      def initialize
        @slug = ''
        @visit = ''
        @charts = []
        @webservers = []
        parse_yaml_file
      end

      def parse_yaml_file
        spout_config = YAML.load_file('.spout.yml')

        if spout_config.kind_of?(Hash)
          @slug = spout_config['slug'].to_s.strip
          @visit = spout_config['visit'].to_s.strip

          @charts = if spout_config['charts'].kind_of?(Array)
            spout_config['charts'].select{|c| c.kind_of?(Hash)}
          else
            []
          end

          @webservers = if spout_config['webservers'].kind_of?(Array)
            spout_config['webservers'].select{|c| c.kind_of?(Hash)}
          else
            []
          end
        else
          puts "The YAML file needs to be in the following format:"
          puts "---\nvisit: visit_variable_name\ncharts:\n- chart: age_variable_name\n  title: Age\n- chart: gender_variable_name\n  title: Gender\n- chart: race_variable_name\n  title: Race\n"
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spout-0.10.2 lib/spout/helpers/config_reader.rb
spout-0.10.1 lib/spout/helpers/config_reader.rb
spout-0.10.0 lib/spout/helpers/config_reader.rb
spout-0.10.0.rc3 lib/spout/helpers/config_reader.rb
spout-0.10.0.rc2 lib/spout/helpers/config_reader.rb
spout-0.10.0.rc lib/spout/helpers/config_reader.rb
spout-0.10.0.beta10 lib/spout/helpers/config_reader.rb
spout-0.10.0.beta9 lib/spout/helpers/config_reader.rb
spout-0.10.0.beta8 lib/spout/helpers/config_reader.rb
spout-0.10.0.beta7 lib/spout/helpers/config_reader.rb
spout-0.10.0.beta6 lib/spout/helpers/config_reader.rb