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
- #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.
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
#context ⇒ Object
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 |
#current ⇒ Object
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
.current ⇒ Object
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 |