Sha256: 23568c50d92d95de97dc3fff5c2f7b451ac331183bbabda9774e6a11b5979a95

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require 'logger'
require "yaml"
require "duniversity/version"
require "duniversity/saudacao/logger"

module Duniversity
  class Saudacao
    attr_accessor :config

    def initialize(yaml_path)
      self.config= {
          :log_path => "/tmp/saudacao.log",
          :ola_txt => "Ola!"
      }

      @valid_keys = {
          :log_path => "",
          :ola_txt => "",
      }

      begin
        data = YAML::load(IO.read(yaml_path))
      rescue Exception => e
        puts "Problema ao carregar YAML com erro #{e.message} para o caminho #{yaml_path}"
        exit(1)
      end

      data.each {|k,v|
        self.config[k.to_sym] = v if @valid_keys.include? k.to_sym
      }
      self.logger= Logger.new(config[:log_path])
      self.logger.debug "Inicializado com sucesso"
    end

    def ola
      self.config[:ola_txt]
    end

    def sauda
      case Time.new.hour
        when 0...12
          "Bom dia!"
        when 12...18
          "Boa tarde"
        else
          "Boa Noite"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duniversity-0.0.1 lib/duniversity.rb