Sha256: c616b3ae0fc236317c323363211df1fd4db41220a65d2c800bb04c914bae847b

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require_relative "habluhablu/version"

# 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
    if File.exist?("./languages/#{language}.yml").eql?(false)
      raise WrongSymbolError.new(language)
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
habluhablu-0.1.6 lib/habluhablu.rb
habluhablu-0.1.4 lib/habluhablu.rb