Module: InstVarsToHash
- Included in:
- AcademicBenchmarks::Standards::Authority, AcademicBenchmarks::Standards::Course, AcademicBenchmarks::Standards::Document, AcademicBenchmarks::Standards::Grade, AcademicBenchmarks::Standards::HasRelations, AcademicBenchmarks::Standards::Parent, AcademicBenchmarks::Standards::Standard, AcademicBenchmarks::Standards::Subject, AcademicBenchmarks::Standards::SubjectDoc
- Defined in:
- lib/academic_benchmarks/lib/inst_vars_to_hash.rb
Overview
This module will allow you to properly to_s, to_h, and to_json on classes in which it is included.
It is not intended to be general purpose, but rather should be used only with standards and standards-related data structures, which themselves are mirrors of the JSON definitions used by Academic Benchmarks
Instance Method Summary collapse
- #to_h(omit_parent: true, omit_empty_children: true) ⇒ Object
- #to_json(omit_parent: true, omit_empty_children: true) ⇒ Object
- #to_s(omit_parent: true, omit_empty_children: true) ⇒ Object
Instance Method Details
#to_h(omit_parent: true, omit_empty_children: true) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/academic_benchmarks/lib/inst_vars_to_hash.rb', line 19 def to_h(omit_parent: true, omit_empty_children: true) retval = {} instance_variables.each do |iv| if !(skip_parent?(omit_parent, iv) || skip_children?(omit_empty_children, iv)) retval[iv.to_s.delete('@').to_sym] = elem_to_h(instance_variable_get(iv)) end end retval end |
#to_json(omit_parent: true, omit_empty_children: true) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/academic_benchmarks/lib/inst_vars_to_hash.rb', line 29 def to_json(omit_parent: true, omit_empty_children: true) to_h( omit_parent: omit_parent, omit_empty_children: omit_empty_children ).to_json end |
#to_s(omit_parent: true, omit_empty_children: true) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/academic_benchmarks/lib/inst_vars_to_hash.rb', line 12 def to_s(omit_parent: true, omit_empty_children: true) to_h( omit_parent: omit_parent, omit_empty_children: omit_empty_children ).to_s end |