Sha256: e1ff63c2ea4c415b82e836279bbd66177f5d71fa470cfdfd7546594664acc697

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_relative "habluhablu/version"
require_relative "languages/languages"

# Module HabluHablu
module Habluhablu
  class Error < StandardError; end

  # Cutom error with helpful message
  class WrongSymbolError < Error
    def initialize(language)
      super("Wrong language symbol: #{language}!")
    end
  end

  # Cutom error with helpful message
  class GemI18nError < Error
    def initialize
      super("Install I18n gem!")
    end
  end

  def self.hablu(language)
    # Check if I18n gem is included
    # if not, raise the custom error
    if Dir.exist?("./config/locales").eql?(false)
      raise GemI18nError.new
    end

    # Check if specified symbol's language does exist
    # if not, raise the custom error
    language_class = Languages.new(language)
    if language_class.include_language? == false
      raise WrongSymbolError.new(language)
    end

    # Create a file of specified language
    File.open("./config/locales/#{language}.yml", "w") do |f|
      f.write(language_class.render)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
habluhablu-0.2.2 lib/habluhablu.rb
habluhablu-0.2.1 lib/habluhablu.rb
habluhablu-0.2.0 lib/habluhablu.rb
habluhablu-0.1.9 lib/habluhablu.rb
habluhablu-0.1.8 lib/habluhablu.rb