Class: TestCentricity::DataPresenter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ DataPresenter

Returns a new instance of DataPresenter.



37
38
39
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 37

def initialize(data)
  self.attributes = data
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



35
36
37
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 35

def context
  @context
end

#currentObject

Returns the value of attribute current.



34
35
36
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 34

def current
  @current
end

Class Method Details

.currentObject



41
42
43
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 41

def self.current
  @current
end

.current=(current) ⇒ Object



45
46
47
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 45

def self.current=(current)
  @current = current
end

Instance Method Details

#to_hash(node_name = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 49

def to_hash(node_name = nil)
  data = {}
  if node_name.nil?
    data = { class: self.class.name, attributes: self.attributes }
  else
    data[node_name] = { class: self.class.name, attributes: self.attributes }
  end
  data
end

#to_json(node_name = nil) ⇒ Object



68
69
70
71
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 68

def to_json(node_name = nil)
  data = to_hash(node_name)
  data.to_json
end

#to_yaml(node_name = nil) ⇒ Object



59
60
61
62
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 59

def to_yaml(node_name = nil)
  data = to_hash(node_name)
  data.to_yaml
end

#write_json_data(file_name, mode, node_name = nil) ⇒ Object



73
74
75
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 73

def write_json_data(file_name, mode, node_name = nil)
  File.open(file_name, mode) { |file| file.write(to_json(node_name)) }
end

#write_yaml_data(file_name, mode, node_name = nil) ⇒ Object



64
65
66
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 64

def write_yaml_data(file_name, mode, node_name = nil)
  File.open(file_name, mode) { |file| file.write(to_yaml(node_name)) }
end