Class: CIAT::TestFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ciat/test_file.rb

Overview

:nodoc:all

Instance Method Summary collapse

Constructor Details

#initialize(test_file, output_folder) ⇒ TestFile

Returns a new instance of TestFile.



3
4
5
6
7
8
9
# File 'lib/ciat/test_file.rb', line 3

def initialize(test_file, output_folder)
  unless File.exists?(test_file)
    raise IOError.new(test_file + " does not exist")
  end
  @test_file = test_file
  @output_folder = output_folder
end

Instance Method Details

#filename(*modifiers) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ciat/test_file.rb', line 11

def filename(*modifiers)
  if modifiers == [:ciat]
    @test_file
  else
    File.join(@output_folder, [stub, *modifiers].compact.join("_"))
  end
end

#groupingObject



19
20
21
# File 'lib/ciat/test_file.rb', line 19

def grouping
  File.dirname(@test_file)
end

#processObject

:nodoc:



23
24
25
26
27
28
29
# File 'lib/ciat/test_file.rb', line 23

def process #:nodoc:
  elements = empty_elements_hash
  split.each do |name, contents|
    elements[name] = CIAT::TestElement.new(name, filename(name), contents)
  end
  elements
end

#splitObject

:nodoc:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ciat/test_file.rb', line 31

def split #:nodoc:
  tag = :description
  content = ""
  raw_elements = {}
  read.each do |line|
    if line =~ /^==== ((\w|\s)+?)\W*$/
      raw_elements[tag] = content
      tag = $1.gsub(" ", "_").to_sym
      content = ""
    else
      content += line
    end
  end
  raw_elements[tag] = content
  raw_elements
end