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"]
BLANKED_PREFIX =
"blanked_"
DETAILS_FIELDS =
"details_fields"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RequestStats.



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

def initialize(type:, requests: [])
  raise "type should be one of #{Eco::API::Session::Batch::Job.types}. Given: #{type}"  unless self.class.valid_type?(type.to_sym)
  @type  = type.to_sym
  @count = requests && 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.



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

def type
  @type
end

Class Method Details

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



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

def (stats: false, all: false)
  ACCOUNT_ATTRS.dup.tap do |attrs|
    if stats || all
      attrs.unshift("account_remove")
      attrs.unshift("account") if all
      attrs.concat(blank_attrs(ACCOUNT_ATTRS))
    end
  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



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

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



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

def core_attrs(stats: false, all: false)
  CORE_ATTRS.dup.tap do |attrs|
    if stats || all
      attrs.unshift("core")
      attrs.concat(blank_attrs(CORE_ATTRS))
    end
  end
end

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



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

def details_attrs(stats: false, all: false)
  DETAILS_ATTRS.dup.tap do |attrs|
    if stats || all
      attrs.unshift("details_remove")
      attrs.unshift("details") if all
    end
  end
end

.valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#message(percent: false) ⇒ Object



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

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



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

def to_h
  @stats
end