Sha256: 6ec753d1c30ae2f448171f57775d38dc9de7f43c9191865965a2110b3db0258e

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'pry'
module BabelDiff
  class ImportFileHandler < Struct.new(:import_directory, :phrase_directory)

    def phrases
      phrase_files = Dir.glob(phrase_directory + '/*.yml').map {|f| PhraseFile.new(f) }
      import_files = Dir.glob(import_directory + '/*/*.yml').map {|f| ImportFile.new(f) }

      matched_files = {}

      phrase_files.each do |phrase|
        if matched_import = import_files.detect {|i| i.language == phrase.language }
          matched_files[phrase.language] = [phrase.contents, matched_import.contents]
        end
      end

      matched_files
    end

    def update_phrase(language, contents)
      File.open(phrase_directory + "/phrase.#{language}.yml", "w+") do |file|
        file.write(contents)
      end
    end

    class PhraseFile < Struct.new(:path)

      def language
        path.split("/").last.match(/phrase.(.*).yml/)[1]
      end

      def contents
        File.read(path)
      end

    end

    class ImportFile < Struct.new(:path)

      def language
        path.split("/")[-2]
      end

      def contents
        File.read(path)
      end

    end


  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
babel_diff-1.1.0 lib/babel_diff/import_file_handler.rb