Class: ProjectData

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/asker/data/project_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectData

Returns a new instance of ProjectData.



9
10
11
# File 'lib/asker/data/project_data.rb', line 9

def initialize
  reset
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



7
8
9
# File 'lib/asker/data/project_data.rb', line 7

def default
  @default
end

#paramObject (readonly)

Returns the value of attribute param.



7
8
9
# File 'lib/asker/data/project_data.rb', line 7

def param
  @param
end

Instance Method Details

#get(key) ⇒ Object



23
24
25
26
27
# File 'lib/asker/data/project_data.rb', line 23

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

  @default[key]
end

#openObject

Open new project

  • setting new params and

  • creating output files

IMPORTANT: We need at least these values

  • process_file

  • inputdirs



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/asker/data/project_data.rb', line 40

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

#resetObject



13
14
15
16
17
18
19
20
21
# File 'lib/asker/data/project_data.rb', line 13

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

#set(key, value) ⇒ Object



29
30
31
# File 'lib/asker/data/project_data.rb', line 29

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