lib/attributes_json.rb
# Implements a sane default `as_json` for an object
# that accessors defined
#
# @param root[Bool] if true, it surrounds the result in a hash with a key
#  `format_parser_file_info`
# @param stringify_keys[Bool] if true, it transforms all the hash keys to a string.
#   The default value is false for backward compatibility
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, stringify_keys: 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(/\=$/, '')
      attribute_value = public_send(reader_method_name)
      unwrapped_attribute_value = attribute_value.respond_to?(:as_json) ? attribute_value.as_json : attribute_value
      sanitized_value = _sanitize_json_value(unwrapped_attribute_value)
      h[reader_method_name] = sanitized_value
    end
    h = FormatParser::HashUtils.deep_transform_keys(h, &:to_s) if stringify_keys
    if root
      {'format_parser_file_info' => h}
    else
      h
    end
  end
def as_json ( root : false , stringify_keys : 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 ( / \= $ / , '' ) attribute_value = public_send ( reader_method_name ) unwrapped_attribute_value = attribute_value . respond_to? ( :as_json ) ? attribute_value . as_json : attribute_value sanitized_value = _sanitize_json_value ( unwrapped_attribute_value ) h [ reader_method_name ] = sanitized_value end h = FormatParser :: HashUtils . deep_transform_keys ( h , & :to_s ) if stringify_keys 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
if true, it surrounds the result in a hash with a key `format_parser_file_info`
if true it surrounds the result in a hash with a key ` format_parser_file_info `
stringify_keys
if true, it transforms all the hash keys to a string. The default value is false for backward compatibility
if true it transforms all the hash keys to a string . The default value is false for backward compatibility