Class: TestCentricity::DataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/testcentricity_apps/data_objects/data_objects_helper.rb

Overview

:nocov:

Direct Known Subclasses

EnvironData

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



55
56
57
# File 'lib/testcentricity_apps/data_objects/data_objects_helper.rb', line 55

def file_path
  @file_path
end

#nodeObject

Returns the value of attribute node.



55
56
57
# File 'lib/testcentricity_apps/data_objects/data_objects_helper.rb', line 55

def node
  @node
end

Class Method Details

.calculate_dynamic_value(value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/testcentricity_apps/data_objects/data_objects_helper.rb', line 74

def self.calculate_dynamic_value(value)
  test_value = value.split('!', 2)
  parameter = test_value[1].split('.', 2)
  case parameter[0]
  when 'Date'
    result = eval("Chronic.parse('#{parameter[1]}')")
  when 'FormattedDate', 'FormatDate'
    date_time_params = parameter[1].split(' format! ', 2)
    date_time = eval("Chronic.parse('#{date_time_params[0].strip}')")
    result = date_time.to_s.format_date_time("#{date_time_params[1].strip}")
  else
    result = if Faker.constants.include?(parameter[0].to_sym)
               eval("Faker::#{parameter[0]}.#{parameter[1]}")
             else
               eval(test_value[1])
             end
  end
  result.to_s
end

Instance Method Details

#read_json_node_data(file_name, node_name) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/testcentricity_apps/data_objects/data_objects_helper.rb', line 64

def read_json_node_data(file_name, node_name)
  @file_path = "#{PRIMARY_DATA_PATH}#{file_name}"
  @node = node_name
  raw_data = File.read(@file_path)
  data = JSON.parse(raw_data)
  data[node_name]
end

#read_yaml_node_data(file_name, node_name) ⇒ Object



57
58
59
60
61
62
# File 'lib/testcentricity_apps/data_objects/data_objects_helper.rb', line 57

def read_yaml_node_data(file_name, node_name)
  @file_path = "#{PRIMARY_DATA_PATH}#{file_name}"
  @node = node_name
  data = YAML.load_file(@file_path)
  data[node_name]
end