Class: Poke::CurlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/poke/curl_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ CurlParser

Returns a new instance of CurlParser.



9
10
11
12
13
14
15
# File 'lib/poke/curl_parser.rb', line 9

def initialize(content)
  @content = content
  @comments = []
  @arguments = []
  @url = nil
  parse
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



7
8
9
# File 'lib/poke/curl_parser.rb', line 7

def arguments
  @arguments
end

#commentsObject (readonly)

Returns the value of attribute comments.



7
8
9
# File 'lib/poke/curl_parser.rb', line 7

def comments
  @comments
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/poke/curl_parser.rb', line 7

def url
  @url
end

Instance Method Details

#add_argument(arg) ⇒ Object



33
34
35
# File 'lib/poke/curl_parser.rb', line 33

def add_argument(arg)
  @arguments << arg
end

#remove_argument(pattern) ⇒ Object



37
38
39
# File 'lib/poke/curl_parser.rb', line 37

def remove_argument(pattern)
  @arguments.reject! { |arg| arg.match?(pattern) }
end

#replace_argument(pattern, replacement) ⇒ Object



41
42
43
44
45
# File 'lib/poke/curl_parser.rb', line 41

def replace_argument(pattern, replacement)
  @arguments.map! do |arg|
    arg.match?(pattern) ? replacement : arg
  end
end

#to_commandObject



17
18
19
20
21
22
# File 'lib/poke/curl_parser.rb', line 17

def to_command
  parts = ['curl']
  parts.concat(@arguments)
  parts << @url if @url
  parts.join(' ')
end

#to_command_with_line_continuationObject



24
25
26
27
28
29
30
31
# File 'lib/poke/curl_parser.rb', line 24

def to_command_with_line_continuation
  parts = ['curl']
  parts.concat(@arguments)
  parts << @url if @url
  
  # Join with line continuation for better readability
  parts.join(" \\\n  ")
end