Class: Vedeu::Renderers::JSON

Inherits:
File
  • Object
show all
Includes:
Options
Defined in:
lib/vedeu/renderers/json.rb

Overview

Renders a Buffers::Terminal as JSON.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsHash<Symbol => void> Originally defined in module Options

Returns:

  • (Hash<Symbol => void>)

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#as_hashArray (private)

Returns:

  • (Array)


23
24
25
# File 'lib/vedeu/renderers/json.rb', line 23

def as_hash
  output.content.map(&:to_h)
end

#become(klass, attributes) ⇒ Class Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#clearvoid

This method returns an undefined value.

Render a cleared output.



16
17
18
# File 'lib/vedeu/renderers/json.rb', line 16

def clear
  render({})
end

#compressionString (private) Originally defined in module Options

Compresses the output depending on configuration.

Returns:

  • (String)

#compression?Boolean (private) Originally defined in module Options

Returns a boolean indicating whether the content should be compressed if compression is available.

Returns:

#contentString (private)

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vedeu/renderers/json.rb', line 28

def content
  if hash?(output)
    ::JSON.pretty_generate(output)

  else
    Vedeu.log(type:    :render,
              message: "#{self.class.name}#content: #{output.class.name}")

    ::JSON.pretty_generate(as_hash)
  end
end

#default_templateString (private) Originally defined in module Options

Returns:

  • (String)

#defaultsHash<Symbol => void> (private) Originally defined in module Options

The default values for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)

#end_row_tagString (private) Originally defined in module Options

Returns:

  • (String)

#end_tagString (private) Originally defined in module Options

Returns:

  • (String)

#escape?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#filenameString (private) Originally defined in module Options

Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.

Returns:

  • (String)

#hash?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#initialize(opts = {}) ⇒ void Originally defined in module Options

Returns a new instance of the class including this module.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • content (String)

    Defaults to an empty string.

  • end_tag (String)

    Defaults to ‘</td>’.

  • end_row_tag (String)

    Defaults to ‘</tr>’.

  • filename (String)

    Provide a filename for the output. Defaults to ‘out’.

  • start_tag (String)

    Defaults to ‘<td’ (note the end of the tag is missing, this is so that inline styles can be added later).

  • start_row_tag (String)

    Defaults to ‘<tr>’.

  • template (String)
  • timestamp (Boolean)

    Append a timestamp to the filename.

  • write_file (Boolean)

    Whether to write the file to the given filename.

#line_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Line.

Returns:

#numeric?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#outputvoid (private) Originally defined in module Options

This method returns an undefined value.

#output?Boolean (private) Originally defined in module Options

Returns:

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#render(output = '') ⇒ void Originally defined in module Options

This method returns an undefined value.

Parameters:

#snake_case(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#start_row_tagString (private) Originally defined in module Options

Returns:

  • (String)

#start_tagString (private) Originally defined in module Options

Returns:

  • (String)

#stream_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#templateString (private) Originally defined in module Options

Returns:

  • (String)

#timestampString (private) Originally defined in module Options

Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.

Returns:

  • (String)

#timestamp?Boolean (private) Originally defined in module Options

Returns:

#truthy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#view_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::View.

Returns:

#writeObject Originally defined in module Options

Raises:

  • (Vedeu::Error::NotImplemented)

    When a subclass of the current class actually implements the method. Usually an indicator that the subclass should be used instead of the current class.

#write_fileString (private) Originally defined in module Options

Render the output (either content or clearing) to a file.

Returns:

  • (String)

#write_file?Boolean (private) Originally defined in module Options

Returns a boolean indicating whether a file should be written.

Returns: