Class: Eco::API::Organization::NodeClassifications

Inherits:
Language::Models::Collection show all
Defined in:
lib/eco/api/organization/node_classifications.rb

Constant Summary

Constants inherited from Language::Models::Collection

Language::Models::Collection::BASIC_METHODS, Language::Models::Collection::EXTENDED_METHODS

Instance Method Summary collapse

Methods inherited from Language::Models::Collection

#<, #<<, #attr, #attr?, attr_collection, attr_presence, #attrs, attrs_create_method, #contains, #delete!, #each, #empty, #empty?, #exclude, #group_by, #length, #merge, #new, #newFrom, #present, #present_all?, #present_some?, #remove, #to_c, #to_h, #unique_attrs, #update

Constructor Details

#initialize(types = [], klass: Ecoportal::API::GraphQL::Base::LocationClassificationType) ⇒ NodeClassifications

rubocop:disable Lint/UnusedMethodArgument



8
9
10
11
12
13
# File 'lib/eco/api/organization/node_classifications.rb', line 8

def initialize(types = [], klass: Ecoportal::API::GraphQL::Base::LocationClassificationType) # rubocop:disable Lint/UnusedMethodArgument
  @klass       = Ecoportal::API::GraphQL::Base::LocationClassificationType
  @caches_init = false
  super(types, klass: @klass)
  init_caches
end

Instance Method Details

#[](id_name) ⇒ Object



49
50
51
# File 'lib/eco/api/organization/node_classifications.rb', line 49

def [](id_name)
  @by_id[type_id(id_name)]
end

#idsObject



15
16
17
# File 'lib/eco/api/organization/node_classifications.rb', line 15

def ids
  @items.map(&:id)
end

#namesObject



19
20
21
# File 'lib/eco/api/organization/node_classifications.rb', line 19

def names
  @items.map(&:name)
end

#to_id(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/eco/api/organization/node_classifications.rb', line 23

def to_id(name)
  case name
  when Enumerable
    name.map do |n|
      type(n)&.id
    end.compact
  else
    type(name)&.id
  end
end

#to_name(id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/eco/api/organization/node_classifications.rb', line 34

def to_name(id)
  case id
  when Enumerable
    id.map do |n|
      type(n)&.name
    end.compact
  else
    type(id)&.name
  end
end

#type(id_name) ⇒ Object



45
46
47
# File 'lib/eco/api/organization/node_classifications.rb', line 45

def type(id_name)
  self[id_name]
end