Class: TestCentricity::DataPresenter
- Defined in:
- lib/testcentricity_web/data_objects/data_objects_helper.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#current ⇒ Object
Returns the value of attribute current.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ DataPresenter
constructor
A new instance of DataPresenter.
-
#to_hash(node_name = nil) ⇒ Object
:nocov:.
- #to_json(node_name = nil) ⇒ Object
- #to_yaml(node_name = nil) ⇒ Object
- #write_json_data(file_name, mode, node_name = nil) ⇒ Object
- #write_yaml_data(file_name, mode, node_name = nil) ⇒ Object
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
#context ⇒ Object
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 |
#current ⇒ Object
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
.current ⇒ Object
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
:nocov:
56 57 58 59 60 61 62 63 64 |
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 56 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
75 76 77 78 |
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 75 def to_json(node_name = nil) data = to_hash(node_name) data.to_json end |
#to_yaml(node_name = nil) ⇒ Object
66 67 68 69 |
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 66 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
80 81 82 |
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 80 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
71 72 73 |
# File 'lib/testcentricity_web/data_objects/data_objects_helper.rb', line 71 def write_yaml_data(file_name, mode, node_name = nil) File.open(file_name, mode) { |file| file.write(to_yaml(node_name)) } end |