Class: Hiiro::Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/hiiro/capture.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.at_offset(n) ⇒ Object

Fetch the capture at offset n from the most recent (0 = newest).



24
25
26
# File 'lib/hiiro/capture.rb', line 24

def self.at_offset(n)
  order(Sequel.desc(:id)).offset(n.to_i).first
end

.create_table!(db) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/hiiro/capture.rb', line 7

def self.create_table!(db)
  db.create_table?(:captures) do
    primary_key :id
    String :name, null: false
    String :path, null: false
    String :command
    Integer :exit_status
  end
end

.recent(limit = nil) ⇒ Object

Most-recent-first scope. id is autoincrement, so desc(:id) == chronological reverse.



18
19
20
21
# File 'lib/hiiro/capture.rb', line 18

def self.recent(limit = nil)
  ds = order(Sequel.desc(:id))
  limit ? ds.limit(limit).all : ds.all
end

Instance Method Details

#display_string(idx) ⇒ Object



36
37
38
39
40
# File 'lib/hiiro/capture.rb', line 36

def display_string(idx)
  cmd = command.to_s
  cmd = cmd[0, 57] + '' if cmd.length > 60
  format("%4d. %s  %-22s  %s", idx, status_glyph, name, cmd)
end

#status_glyphObject



28
29
30
31
32
33
34
# File 'lib/hiiro/capture.rb', line 28

def status_glyph
  case exit_status
  when 0   then "\e[32m✓\e[0m"
  when nil then "\e[33m?\e[0m"
  else          "\e[31m✗\e[0m"
  end
end