Class: CIAT::CiatFile

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

Overview

:nodoc:all

Instance Method Summary collapse

Constructor Details

#initialize(ciat_file, output_folder) ⇒ CiatFile

Returns a new instance of CiatFile.



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

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

Instance Method Details

#element(*names) ⇒ Object



15
16
17
# File 'lib/ciat/ciat_file.rb', line 15

def element(*names)
  elements[names.compact.join("_").to_sym]
end

#element?(*names) ⇒ Boolean

Returns:

  • (Boolean)


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

def element?(*names)
  elements.has_key?(names.compact.join("_").to_sym)
end

#elementsObject



11
12
13
# File 'lib/ciat/ciat_file.rb', line 11

def elements
  @elements ||= process
end

#filename(*modifiers) ⇒ Object



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

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

#groupingObject



31
32
33
# File 'lib/ciat/ciat_file.rb', line 31

def grouping
  File.dirname(@ciat_file)
end

#processObject

:nodoc:



35
36
37
38
39
40
41
# File 'lib/ciat/ciat_file.rb', line 35

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:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ciat/ciat_file.rb', line 43

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