Module: OpenHAB::Console::IRB::EntityCompletor

Defined in:
lib/openhab/console/irb.rb

Constant Summary collapse

VALID_ENTITY_PREFIXES =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"

Instance Method Summary collapse

Instance Method Details

#completion_candidates(_preposing, target, _postposing, bind:) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/openhab/console/irb.rb', line 68

def completion_candidates(_preposing, target, _postposing, bind:)
  return super unless defined?(OpenHAB::Core::EntityLookup)
  return super unless VALID_ENTITY_PREFIXES.include?(target[0])

  this = bind.eval("self")
  return super unless this.is_a?(OpenHAB::Core::EntityLookup)

  matching_items = OpenHAB::DSL.items.filter_map do |item|
    item.name if item.name.start_with?(target)
  end
  matching_things = OpenHAB::DSL.things.filter_map do |thing|
    id = thing.uid.to_s.tr(":", "_")
    id if id.start_with?(target)
  end
  matching_items | matching_things | super
end