Sha256: bd92c8959276c65cd69dec51626ed2a4416005c02afec091d3600928eaa76a85

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

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.is_a?(Hash)
          @slug = spout_config['slug'].to_s.strip
          @visit = spout_config['visit'].to_s.strip

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

          @webservers = if spout_config['webservers'].is_a?(Array)
            spout_config['webservers'].select{|c| c.is_a?(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

7 entries across 7 versions & 1 rubygems

Version Path
spout-0.12.1 lib/spout/helpers/config_reader.rb
spout-0.12.0 lib/spout/helpers/config_reader.rb
spout-0.12.0.rc2 lib/spout/helpers/config_reader.rb
spout-0.12.0.rc lib/spout/helpers/config_reader.rb
spout-0.12.0.beta2 lib/spout/helpers/config_reader.rb
spout-0.12.0.beta1 lib/spout/helpers/config_reader.rb
spout-0.11.1 lib/spout/helpers/config_reader.rb