Sha256: b3ee12bc75f75e9d11640db696aac39fbf686771e50dcfed9dbb3b3e333cd3aa

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "singleton"

class ProjectData
  include Singleton
  attr_reader :default, :param

  def initialize
    reset
  end

  def reset
    # @default = {inputbasedir: FileUtils.pwd,
    @default = {inputbasedir: Dir.pwd,
                stages: {d: true, b: true, f: true, i: true, s: true, t: true},
                threshold: 0.5,
                outputdir: "output",
                weights: "1, 1, 1"}
    @param = {}
  end

  def get(key)
    return @param[key] unless @param[key].nil?

    @default[key]
  end

  def set(key, value)
    @param[key] = value
  end

  ##
  # Open new project
  # * setting new params and
  # * creating output files
  # IMPORTANT: We need at least these values
  # * process_file
  # * inputdirs
  def open
    ext = File.extname(@param[:process_file]) || ".haml"
    @param[:projectname] = @param[:projectname] ||
      File.basename(@param[:process_file], ext)

    @param[:logname] = "#{@param[:projectname]}.log"
    @param[:outputname] = "#{@param[:projectname]}-gift.txt"
    @param[:lessonname] = "#{@param[:projectname]}.txt"
    @param[:yamlname] = "#{@param[:projectname]}.yaml"
    @param[:moodlename] = "#{@param[:projectname]}-moodle.xml"

    outputdir = get(:outputdir)
    @param[:logpath] = File.join(outputdir, get(:logname))
    @param[:outputpath] = File.join(outputdir, get(:outputname))
    @param[:lessonpath] = File.join(outputdir, get(:lessonname))
    @param[:yamlpath] = File.join(outputdir, get(:yamlname))
    @param[:moodlepath] = File.join(outputdir, get(:moodlename))

    Dir.mkdir(outputdir) unless Dir.exist?(outputdir)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
asker-tool-2.9.4 lib/asker/data/project_data.rb
asker-tool-2.9.3 lib/asker/data/project_data.rb
asker-tool-2.9.2 lib/asker/data/project_data.rb
asker-tool-2.9.1 lib/asker/data/project_data.rb
asker-tool-2.9.0 lib/asker/data/project_data.rb