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) ⇒ Object



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

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

#to_json(node_name) ⇒ Object



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

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

#to_yaml(node_name) ⇒ Object



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

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

#write_json_data(file_name, mode, node_name) ⇒ Object



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

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

#write_yaml_data(file_name, mode, node_name) ⇒ Object



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

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