Class: Tabry::Models::SubsList

Inherits:
ConfigList show all
Defined in:
lib/tabry/models/subs_list.rb

Instance Attribute Summary

Attributes inherited from ConfigList

#unflattened

Instance Method Summary collapse

Methods inherited from ConfigList

#[], #as_json, #each, #empty?, #flatten, #length, #to_a

Constructor Details

#initialize(**args) ⇒ SubsList

Returns a new instance of SubsList.



9
10
11
# File 'lib/tabry/models/subs_list.rb', line 9

def initialize(**args)
  super(**args, klass: Sub)
end

Instance Method Details

#by_nameObject



13
14
15
# File 'lib/tabry/models/subs_list.rb', line 13

def by_name
  @by_name ||= to_a.to_h { |sub| [sub.name, sub] }
end

#match(token) ⇒ Object



17
18
19
20
21
# File 'lib/tabry/models/subs_list.rb', line 17

def match(token)
  to_a.find do |sub|
    [sub.name, *sub.aliases].include?(token)
  end
end

#options(token, params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tabry/models/subs_list.rb', line 23

def options(token, params)
  ::Tabry::Util.debug "checking:::: #{token}"
  to_a
    .select { |sub| sub.name.start_with?(token) }
    .map do |sub|
      if params[:descriptions]
        [sub.name, sub.description]
      else
        sub.name
      end
    end
    .compact
end