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) ⇒ Object
- #to_json(omit_parent: true) ⇒ Object
- #to_s(omit_parent: true) ⇒ Object
Instance Method Details
#to_h(omit_parent: true) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/academic_benchmarks/lib/inst_vars_to_hash.rb', line 17 def to_h(omit_parent: true) retval = {} instance_variables.each do |iv| unless omit_parent && (iv =~ /^@?parent$/i) retval[iv.to_s.delete('@').to_sym] = elem_to_h(instance_variable_get(iv)) end end retval end |
#to_json(omit_parent: true) ⇒ Object
27 28 29 |
# File 'lib/academic_benchmarks/lib/inst_vars_to_hash.rb', line 27 def to_json(omit_parent: true) to_h(omit_parent: omit_parent).to_json end |
#to_s(omit_parent: true) ⇒ Object
13 14 15 |
# File 'lib/academic_benchmarks/lib/inst_vars_to_hash.rb', line 13 def to_s(omit_parent: true) to_h(omit_parent: omit_parent).to_s end |