Module: VanillaUtilityReader::VanillaFileReader::PageRepoReader
- Defined in:
- lib/vanilla_utility_reader/file_utility/page_repo_reader.rb
Instance Method Summary collapse
-
#get_element_from_object_repo(file_name, element_name) ⇒ Object
- get_element_from_object_repo
- It reads the particular element from object repository Input
-
File name ( file will be inside object repository of project ), element_name (which is inside the object repo file) $test = VanillaUtilityReader::VanillaFileReader::PageRepoReader $test.get_element_from_object_repo(file_name, element_name).
-
#repo_reader(file_name) ⇒ Object
- repo_reader
-
It reads the object repository from the project which is defined under the object repository $test = VanillaUtilityReader::VanillaFileReader::PageRepoReader $test.repo_reader(file_name).
Instance Method Details
#get_element_from_object_repo(file_name, element_name) ⇒ Object
- get_element_from_object_repo
-
It reads the particular element from object repository
- Input
-
File name ( file will be inside object repository of project ), element_name (which is inside the object repo file)
$test = VanillaUtilityReader::VanillaFileReader::PageRepoReader $test.get_element_from_object_repo(file_name, element_name)
68 69 70 71 |
# File 'lib/vanilla_utility_reader/file_utility/page_repo_reader.rb', line 68 def get_element_from_object_repo(file_name, element_name) elem = repo_reader(file_name) elem[element_name] end |
#repo_reader(file_name) ⇒ Object
- repo_reader
-
It reads the object repository from the project which is defined under the object repository
$test = VanillaUtilityReader::VanillaFileReader::PageRepoReader $test.repo_reader(file_name)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vanilla_utility_reader/file_utility/page_repo_reader.rb', line 8 def repo_reader(file_name) begin dir_path = Dir.pwd dir_file_path = File.("object_repository/", dir_path) repo_set = Dir.entries(dir_file_path) file_name = file_name.split(".") file_name = file_name[0] if repo_set.any? { |s| s.include?(file_name) } if(repo_set.index(file_name+".json") != nil) file_path = dir_file_path+"/#{file_name}.json" begin json = File.read(file_path) locator = JSON.parse(json) rescue Exception => e raise "Json file is not in defined format #{file_path} \n error : #{e.}" end locator elsif(repo_set.index(file_name+".csv") != nil) file_path = dir_file_path+"/#{file_name}.csv" $locators = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc) } begin CSV.foreach(file_path) do |row| for iterator in 1..(row.length-1) if row[iterator].to_s.split("=")[2]==nil $locators[row[0]][row[iterator].split("=")[0]] = row[iterator].split("=")[1] else #TODO Make this part generic to handle multiple occurence of '=' in xpath if required. As of now we dont see need for this scenerio. $locators[row[0]][row[iterator].split("=")[0]] = "#{row[iterator].split("=")[1]}=#{row[iterator].split("=")[2]}" end end end rescue Exception => e raise "Invalid CSV file " + e. end locat = $locators locat #TODO YML support in progress elsif(repo_set.index(file_name+".yml") != nil) file_path = dir_file_path+"/#{file_name}.yml" begin rescue Exception=>e end end end rescue set_path = Dir.pwd file_path = File.("../../object_repository/", set_path) raise "Error in reading Generic Repo Reader \n PATH"+file_path+" \nError :: #{e.}" end end |