Class: ScriptRipper::CLI

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/script_ripper/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#blank?, #present?

Constructor Details

#initialize(arguments = ARGV) ⇒ CLI

Returns a new instance of CLI.



14
15
16
17
# File 'lib/script_ripper/cli.rb', line 14

def initialize(arguments = ARGV)
  @arguments = arguments
  @options = {}
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



12
13
14
# File 'lib/script_ripper/cli.rb', line 12

def arguments
  @arguments
end

#group_nameObject (readonly)

Returns the value of attribute group_name.



12
13
14
# File 'lib/script_ripper/cli.rb', line 12

def group_name
  @group_name
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/script_ripper/cli.rb', line 12

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/script_ripper/cli.rb', line 12

def url
  @url
end

Class Method Details

.call(arguments = ARGV) ⇒ Object



33
34
35
# File 'lib/script_ripper/cli.rb', line 33

def call(arguments = ARGV)
  new(arguments).call
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/script_ripper/cli.rb', line 19

def call
  parse_arguments!

  content = Downloader.call(url)
  code_blocks = Parser.call(content, group_by)

  if code_blocks.is_a?(Hash)
    ScriptWriter.call(code_blocks: code_blocks.fetch(group_name), from_url: url, group_name: group_name)
  else
    ScriptWriter.call(code_blocks: code_blocks, from_url: url)
  end
end

#group_byObject



38
39
40
# File 'lib/script_ripper/cli.rb', line 38

def group_by
  options[:"group-by"]
end