Class: RMuh::RPT::Log::Fetch
- Inherits:
-
Object
- Object
- RMuh::RPT::Log::Fetch
- Includes:
- HTTParty
- Defined in:
- lib/rmuh/rpt/log/fetch.rb
Overview
This is the RPT Log fetcher class. It allows fetching a specific URL, only pulling a specific byte range, as well as getting the size of the external file
Instance Attribute Summary collapse
-
#byte_end ⇒ Object
Returns the value of attribute byte_end.
-
#byte_start ⇒ Object
Returns the value of attribute byte_start.
-
#log_url ⇒ Object
Returns the value of attribute log_url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(log_url, opts = {}) ⇒ Fetch
constructor
New Fetch class.
- #log ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(log_url, opts = {}) ⇒ Fetch
New Fetch class. This is used for fetching the ArmA 2 log files Required param (#1): (String) The log file URL Optional param (#2): (Hash):
-
:byte_start - what byte to start the log file from
-
:byte_end - the last byte that we want from the log file
33 34 35 36 37 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 33 def initialize(log_url, opts = {}) @log_url = log_url @byte_start = opts.fetch(:byte_start, 0) @byte_end = opts.fetch(:byte_end, nil) end |
Instance Attribute Details
#byte_end ⇒ Object
Returns the value of attribute byte_end.
14 15 16 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 14 def byte_end @byte_end end |
#byte_start ⇒ Object
Returns the value of attribute byte_start.
14 15 16 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 14 def byte_start @byte_start end |
#log_url ⇒ Object
Returns the value of attribute log_url.
14 15 16 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 14 def log_url @log_url end |
Class Method Details
.validate_opts(opts) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 16 def self.validate_opts(opts) if opts.key?(:byte_start) && (!opts[:byte_start].is_a?(Fixnum) || opts[:byte_start] < 0) fail(ArgumentError, ':byte_start must be a Fixnum >= 0') end if opts.key?(:byte_end) && ![Fixnum, NilClass].include?(opts[:byte_end].class) fail(ArgumentError, ':byte_end must be nil or Fixnum') end end |
Instance Method Details
#log ⇒ Object
53 54 55 56 57 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 53 def log headers = { 'Range' => "bytes=#{@byte_start}-#{@byte_end}" } response = self.class.get(@log_url, headers: headers) response.lines.map { |l| dos2unix(l).gsub("\n", '') } end |
#size ⇒ Object
49 50 51 |
# File 'lib/rmuh/rpt/log/fetch.rb', line 49 def size self.class.head(@log_url).headers['content-length'].to_i end |