Class: RikaCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/rika/cli/rika_command.rb

Overview

This command line application enables the parsing of documents on the command line. Syntax is:

rika [options] <file or url> [...file or url...]

Run with -h or –help option for more details.

Defaults to outputting both content (text) and metadata, but the -t and -m flags can be used to enable or suppress either. Supports output formats of JSON, Pretty JSON, YAML, Awesome Print, to_s, and inspect (see Formatters class).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ RikaCommand

Returns a new instance of RikaCommand.

Parameters:

  • args (Array<String>) (defaults to: ARGV)

    command line arguments; default to ARGV but may be overridden for testing



21
22
23
24
25
# File 'lib/rika/cli/rika_command.rb', line 21

def initialize(args = ARGV)
  # Dup the array in case it has been frozen. The array will be modified later when options are parsed
  # and removed, and when directories are removed, so this array should not be frozen.
  @args = args.dup
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



18
19
20
# File 'lib/rika/cli/rika_command.rb', line 18

def args
  @args
end

#help_textObject (readonly)

Returns the value of attribute help_text.



18
19
20
# File 'lib/rika/cli/rika_command.rb', line 18

def help_text
  @help_text
end

#metadata_formatterObject (readonly)

Returns the value of attribute metadata_formatter.



18
19
20
# File 'lib/rika/cli/rika_command.rb', line 18

def 
  @metadata_formatter
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/rika/cli/rika_command.rb', line 18

def options
  @options
end

#targetsObject (readonly)

Returns the value of attribute targets.



18
19
20
# File 'lib/rika/cli/rika_command.rb', line 18

def targets
  @targets
end

#text_formatterObject (readonly)

Returns the value of attribute text_formatter.



18
19
20
# File 'lib/rika/cli/rika_command.rb', line 18

def text_formatter
  @text_formatter
end

Instance Method Details

#callObject

Main method and entry point for this class’ work.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rika/cli/rika_command.rb', line 28

def call
  prepare
  report_and_exit_if_no_targets_specified
  if options[:as_array]
    puts result_array_output
  else
    targets.each do |target|
      result = Rika.parse(target, max_content_length: max_content_length, key_sort: options[:key_sort])
      puts single_document_output(target, result)
    end
  end
  nil
end