Class: Chlgr::Command
- Inherits:
-
Object
- Object
- Chlgr::Command
- Defined in:
- lib/chlr/command.rb,
lib/chlr/standard_commands.rb
Constant Summary collapse
- @@commands =
{}
Class Method Summary collapse
- .add(name, &block) ⇒ Object
- .clear ⇒ Object
- .find_all ⇒ Object
- .get(name) ⇒ Object
- .output(dataset, &block) ⇒ Object
- .search(text) ⇒ Object
Class Method Details
.add(name, &block) ⇒ Object
7 8 9 |
# File 'lib/chlr/command.rb', line 7 def add(name, &block) @@commands[name.to_sym] = block end |
.clear ⇒ Object
24 25 26 |
# File 'lib/chlr/command.rb', line 24 def clear @@commands.clear end |
.find_all ⇒ Object
20 21 22 |
# File 'lib/chlr/command.rb', line 20 def find_all @@commands end |
.get(name) ⇒ Object
11 12 13 |
# File 'lib/chlr/command.rb', line 11 def get(name) @@commands[name.to_sym] end |
.output(dataset, &block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/chlr/standard_commands.rb', line 34 def self.output(dataset, &block) puts dataset.limit(10).reverse.map {|log| time = log.created_at.strftime("%Y-%m-%d %X") header = TermColor.parse("<90>-- [##{log.id}] #{time} --</90>") text = block ? block.call(log.text) : log.text "#{header}\n#{text}" }.join("\n") end |
.search(text) ⇒ Object
15 16 17 18 |
# File 'lib/chlr/command.rb', line 15 def search(text) return [] if text.nil? || text.empty? @@commands.keys.map{|i|i.to_s}.grep(/^#{Regexp.quote(text)}/).map{|i|i.to_sym} end |