Class: Eco::API::Session::Batch::RequestStats

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/session/batch/request_stats.rb

Constant Summary collapse

CORE_ATTRS =
Eco::API::Common::People::PersonParser::CORE_ATTRS
ACCOUNT_ATTRS =
(Eco::API::Common::People::PersonParser::ACCOUNT_ATTRS + ['permissions_custom']).uniq
DETAILS_ATTRS =
['fields'].freeze
BLANKED_PREFIX =
'blanked_'.freeze
DETAILS_FIELDS =
'details_fields'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, requests: []) ⇒ RequestStats

Returns a new instance of RequestStats.



65
66
67
68
69
70
71
72
# File 'lib/eco/api/session/batch/request_stats.rb', line 65

def initialize(type:, requests: [])
  msg = "Type should be one of #{Eco::API::Session::Batch::Job.types}. Given: #{type}"
  raise msg unless self.class.valid_type?(type.to_sym)

  @type  = type.to_sym
  @count = requests&.length
  @stats = build(requests)
end

Instance Attribute Details

#countInteger (readonly)

the total number of requests

Returns:

  • (Integer)

    the current value of count



7
8
9
# File 'lib/eco/api/session/batch/request_stats.rb', line 7

def count
  @count
end

#typeObject (readonly)

Returns the value of attribute type.



63
64
65
# File 'lib/eco/api/session/batch/request_stats.rb', line 63

def type
  @type
end

Class Method Details

.account_attrs(stats: false, all: false) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/eco/api/session/batch/request_stats.rb', line 28

def (stats: false, all: false)
  ACCOUNT_ATTRS.dup.tap do |attrs|
    next unless stats || all

    attrs.unshift('account_remove')
    attrs.unshift('account') if all
    attrs.concat(blank_attrs(ACCOUNT_ATTRS))
  end
end

.blank_attrs(attrs) ⇒ Object



58
59
60
# File 'lib/eco/api/session/batch/request_stats.rb', line 58

def blank_attrs(attrs)
  attrs.map {|attr| "#{blanked_prefix}#{attr}"}
end

.blanked_prefix(attr = nil) ⇒ Object



47
48
49
50
51
52
# File 'lib/eco/api/session/batch/request_stats.rb', line 47

def blanked_prefix(attr = nil)
  @blanked_prefix ||= BLANKED_PREFIX
  return @blanked_prefix unless attr

  "#{blanked_prefix}#{attr}"
end

.blanked_prefix=(value) ⇒ Object



54
55
56
# File 'lib/eco/api/session/batch/request_stats.rb', line 54

def blanked_prefix=(value)
  @blanked_prefix = value || blanked_prefix
end

.core_attrs(stats: false, all: false) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/eco/api/session/batch/request_stats.rb', line 19

def core_attrs(stats: false, all: false)
  CORE_ATTRS.dup.tap do |attrs|
    next unless stats || all

    attrs.unshift('core')
    attrs.concat(blank_attrs(CORE_ATTRS))
  end
end

.details_attrs(stats: false, all: false) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/eco/api/session/batch/request_stats.rb', line 38

def details_attrs(stats: false, all: false)
  DETAILS_ATTRS.dup.tap do |attrs|
    next unless stats || all

    attrs.unshift('details_remove')
    attrs.unshift('details') if all
  end
end

.valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/eco/api/session/batch/request_stats.rb', line 15

def valid_type?(type)
  Eco::API::Session::Batch::Job.valid_type?(type.to_sym)
end

Instance Method Details

#message(percent: false) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/eco/api/session/batch/request_stats.rb', line 78

def message(percent: false)
  lines = []
  lines << pairs_to_line(core_pairs(percent: percent))
  lines << pairs_to_line((percent: percent))
  lines << pairs_to_line(details_pairs(percent: percent))
  lines.join("\n")
end

#to_hObject



74
75
76
# File 'lib/eco/api/session/batch/request_stats.rb', line 74

def to_h
  @stats
end