lib/attributes_json.rb
def as_json(root: false)
    h = {}
    h['nature'] = nature if respond_to?(:nature) # Needed for file info structs
    methods.grep(/\w\=$/).each_with_object(h) do |attr_writer_method_name, h|
      reader_method_name = attr_writer_method_name.to_s.gsub(/\=$/, '')
      value = public_send(reader_method_name)
      # When calling as_json on our members there is no need to pass the root: option given to us
      # by the caller
      h[reader_method_name] = value.respond_to?(:as_json) ? value.as_json : value
    end
    if root
      {'format_parser_file_info' => h}
    else
      h
    end
  end
# Implements a sane default `as_json` for an object
# that accessors defined
Implements a sane default `as_json` for an object
that accessors defined
Implements a sane default ` as_json ` for an object that accessors defined
def as_json(root: false)
    h = {}
    h['nature'] = nature if respond_to?(:nature) 
    methods.grep(/\w\=$/).each_with_object(h) do |attr_writer_method_name, h|
      reader_method_name = attr_writer_method_name.to_s.gsub(/\=$/, '')
      value = public_send(reader_method_name)
      h[reader_method_name] = value.respond_to?(:as_json) ? value.as_json : value
    end
    if root
      {'format_parser_file_info' => h}
    else
      h
    end
  end
def as_json ( root : false ) h = { } h [ 'nature' ] = nature if respond_to? ( :nature ) methods . grep ( / \w \= $ / ) . each_with_object ( h ) do | attr_writer_method_name , h | reader_method_name = attr_writer_method_name . to_s . gsub ( / \= $ / , '' ) value = public_send ( reader_method_name ) h [ reader_method_name ] = value . respond_to? ( :as_json ) ? value . as_json : value end if root { 'format_parser_file_info' => h } else h end end
Implements a sane default `as_json` for an object
that accessors defined
Implements a sane default ` as_json ` for an object that accessors defined
# Needed for file info structs # When calling as_json on our members there is no need to pass the root: option given to us # by the caller
root