Class: Claymore::TotalHashRate

Inherits:
Object
  • Object
show all
Includes:
AssetSymbol
Defined in:
lib/claymore/total_hash_rate.rb

Overview

Extracts total hash rate with asset symbol

Example input: 05:45:16:028 2100 ETH - Total Speed: 90.118 Mh/s, Total Shares: 237, Rejected: 0, Time: 06:50

Example output: { ‘asset’ => ‘ETH’, ‘hash_rate’ => 90.118, ‘type’ => ‘TOTAL_HASH_RATE’ }

Constant Summary collapse

TOTAL_RATE_REGEXP =
%r{Total Speed: (?<rate>\d+\.\d+ Mh\/s)}
LINE_REGEXP =
Regexp.new("#{ASSET_REGEXP.source} #{TOTAL_RATE_REGEXP.source}")

Constants included from AssetSymbol

AssetSymbol::ASSET_REGEXP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssetSymbol

#asset_symbol

Constructor Details

#initialize(line) ⇒ TotalHashRate

Returns a new instance of TotalHashRate.



23
24
25
# File 'lib/claymore/total_hash_rate.rb', line 23

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



21
22
23
# File 'lib/claymore/total_hash_rate.rb', line 21

def line
  @line
end

Class Method Details

.call(line) ⇒ Object



17
18
19
# File 'lib/claymore/total_hash_rate.rb', line 17

def self.call(line)
  new(line).call
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
# File 'lib/claymore/total_hash_rate.rb', line 27

def call
  (match = LINE_REGEXP.match(line)) || return

  {
    'asset' => match[:asset],
    'hash_rate' => match[:rate].to_f.round(3),
    'type' => 'TOTAL_HASH_RATE'
  }
end