Class: Eco::API::Session::Batch::RequestStats
- 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
-
#count ⇒ Integer
readonly
the total number of requests.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .account_attrs(stats: false, all: false) ⇒ Object
- .blank_attrs(attrs) ⇒ Object
- .blanked_prefix(attr = nil) ⇒ Object
- .blanked_prefix=(value) ⇒ Object
- .core_attrs(stats: false, all: false) ⇒ Object
- .details_attrs(stats: false, all: false) ⇒ Object
- .valid_type?(type) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(type:, requests: []) ⇒ RequestStats
constructor
A new instance of RequestStats.
- #message(percent: false) ⇒ Object
- #to_h ⇒ Object
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
#count ⇒ Integer (readonly)
the total number of requests
7 8 9 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 7 def count @count end |
#type ⇒ Object (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 account_attrs(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 |
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 (percent: false) lines = [] lines << pairs_to_line(core_pairs(percent: percent)) lines << pairs_to_line(account_pairs(percent: percent)) lines << pairs_to_line(details_pairs(percent: percent)) lines.join("\n") end |
#to_h ⇒ Object
74 75 76 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 74 def to_h @stats end |