Class: TestCentricity::DataSource

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

Direct Known Subclasses

ExcelDataSource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_path ⇒ Object

Returns the value of attribute file_path.



86
87
88
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 86

def file_path
  @file_path
end

#node ⇒ Object

Returns the value of attribute node.



87
88
89
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 87

def node
  @node
end

Class Method Details

.calculate_dynamic_value(value) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 118

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



102
103
104
105
106
107
108
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 102

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



89
90
91
92
93
94
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 89

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

#write_json_node_data(file_name, node_name, node_data) ⇒ Object



110
111
112
113
114
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 110

def write_json_node_data(file_name, node_name, node_data)
  data = read_json_node_data(file_name, node_name)
  data[node_name] = node_data
  File.write(@file_path, data.to_json)
end

#write_yaml_node_data(file_name, node_name, node_data) ⇒ Object



96
97
98
99
100
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 96

def write_yaml_node_data(file_name, node_name, node_data)
  data = read_yaml_node_data(file_name, node_name)
  data[node_name] = node_data
  File.write(@file_path, data.to_yaml)
end