Class: RMuh::RPT::Log::Fetch

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rmuh/rpt/log/fetch.rb

Overview

TODO: Fetch Class documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_url, byte_start = 0, byte_end = nil) ⇒ Fetch

Returns a new instance of Fetch.



14
15
16
17
18
19
20
# File 'lib/rmuh/rpt/log/fetch.rb', line 14

def initialize(log_url, byte_start = 0, byte_end = nil)
  @cfg = OpenStruct.new(
    log_url: log_url,
    byte_start: byte_start,
    byte_end: byte_end
  )
end

Instance Attribute Details

#cfgObject

Returns the value of attribute cfg.



12
13
14
# File 'lib/rmuh/rpt/log/fetch.rb', line 12

def cfg
  @cfg
end

Instance Method Details

#byte_end=(bytes) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rmuh/rpt/log/fetch.rb', line 30

def byte_end=(bytes)
  if bytes.nil? || bytes.is_a?(Integer)
    @cfg.byte_end = bytes
  else
    fail ArgumentError, 'argument 1 must be nil or an integer'
  end
end

#byte_start=(bytes) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rmuh/rpt/log/fetch.rb', line 22

def byte_start=(bytes)
  if bytes.is_a?(Integer)
    @cfg.byte_start = bytes
  else
    fail ArgumentError, 'argument 1 must be an integer'
  end
end

#logObject



42
43
44
45
46
# File 'lib/rmuh/rpt/log/fetch.rb', line 42

def log
  headers = { 'Range' => "bytes=#{@cfg.byte_start}-#{@cfg.byte_end}" }
  response = self.class.get(@cfg.log_url, headers: headers)
  StringIO.new(response.lines.map { |l| dos2unix(l) }.join)
end

#sizeObject



38
39
40
# File 'lib/rmuh/rpt/log/fetch.rb', line 38

def size
  self.class.head(@cfg.log_url).headers['content-length'].to_i
end