Class: CIAT::CiatFile
- Inherits:
-
Object
- Object
- CIAT::CiatFile
- Defined in:
- lib/ciat/ciat_file.rb
Overview
:nodoc:all
Instance Method Summary collapse
- #element(*names) ⇒ Object
- #element?(*names) ⇒ Boolean
- #elements ⇒ Object
- #filename(*modifiers) ⇒ Object
- #grouping ⇒ Object
-
#initialize(ciat_file, output_folder) ⇒ CiatFile
constructor
A new instance of CiatFile.
-
#process ⇒ Object
:nodoc:.
-
#split ⇒ Object
:nodoc:.
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
19 20 21 |
# File 'lib/ciat/ciat_file.rb', line 19 def element?(*names) elements.has_key?(names.compact.join("_").to_sym) end |
#elements ⇒ Object
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 |
#grouping ⇒ Object
31 32 33 |
# File 'lib/ciat/ciat_file.rb', line 31 def grouping File.dirname(@ciat_file) end |
#process ⇒ Object
: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 |
#split ⇒ Object
: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 |