Class: CleverSDK::Data::Districts

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/clever_sdk/data/districts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Districts

private



14
15
16
# File 'lib/clever_sdk/data/districts.rb', line 14

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

private



11
12
13
# File 'lib/clever_sdk/data/districts.rb', line 11

def response
  @response
end

Instance Method Details

#dataObject



18
19
20
# File 'lib/clever_sdk/data/districts.rb', line 18

def data
  @data ||= Array(response.body.dig("data"))
end

#each(&block) ⇒ Object Also known as: all



22
23
24
25
26
27
28
29
# File 'lib/clever_sdk/data/districts.rb', line 22

def each &block
  return enum_for :each unless block

  data
    .lazy
    .map { |datum| CleverSDK::Data::District.new(datum.dig("data"), response) }
    .each(&block)
end

#inspectObject



32
33
34
# File 'lib/clever_sdk/data/districts.rb', line 32

def inspect
  "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} districts:#{data.count}>"
end