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.



43
44
45
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 43

def initialize(data)
  self.attributes = data
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

#currentObject

Returns the value of attribute current.



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

def current
  @current
end

Class Method Details

.currentObject



47
48
49
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 47

def self.current
  @current
end

.current=(current) ⇒ Object



51
52
53
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 51

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

Instance Method Details

#to_hash(node_name = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 55

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



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

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

#to_yaml(node_name = nil) ⇒ Object



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

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



79
80
81
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 79

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



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

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