Class: ConsoleUtils::RequestUtils::Requester

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/console_utils/request_utils/requester.rb

Direct Known Subclasses

Exap, Remo

Constant Summary collapse

INFO_HASH_FIELDS =
url size time human_size human_time).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url


12
13
14
# File 'lib/console_utils/request_utils/requester.rb', line 12

def url
  @url
end

Instance Method Details

#pbcopy(content = nil) ⇒ Object

Copies to pasteboard


26
27
28
29
30
# File 'lib/console_utils/request_utils/requester.rb', line 26

def pbcopy(content = nil)
  content ||= ConsoleUtils::JSONOutput::Default.instance.format_with_fallback(to_s)
  IO.popen('pbcopy', 'w') { |io| io << content.to_s }
  puts PBCOPY_MESSAGE
end

#preview(mth = nil) ⇒ Object


14
15
16
17
18
19
20
21
22
23
# File 'lib/console_utils/request_utils/requester.rb', line 14

def preview(mth = nil)
  if output = to_s.presence
    ConsoleUtils::JSONOutput.formatter.(output)
    show_complete_in!
    show_transfered!
    yield(self) if block_given?
  else
    puts NO_RESPONSE
  end
end

32
33
34
# File 'lib/console_utils/request_utils/requester.rb', line 32

def print_info
  tap { printf(INFO_FORMAT, to_info_hash) }
end

#sizeObject


36
37
38
# File 'lib/console_utils/request_utils/requester.rb', line 36

def size
  @_size.bytes
end

#timeObject


40
41
42
# File 'lib/console_utils/request_utils/requester.rb', line 40

def time
  @_time.in_milliseconds
end

#to_info_hashObject


54
55
56
57
58
# File 'lib/console_utils/request_utils/requester.rb', line 54

def to_info_hash
  hsh = {}
  INFO_HASH_FIELDS.each { |field| hsh[field] = public_send(field) }
  hsh
end