Module: Base::ClassMethods

Defined in:
lib/models/base.rb

Instance Method Summary collapse

Instance Method Details

#allObject



15
16
17
# File 'lib/models/base.rb', line 15

def all
  load
end

#headers_rawObject



19
20
21
# File 'lib/models/base.rb', line 19

def headers_raw
  @headers
end

#load(lines = raw_lines) ⇒ Object



8
9
10
11
12
13
# File 'lib/models/base.rb', line 8

def load(lines = raw_lines)
  @headers = lines.first
  @items = lines[1..-1].map do |line|
    create(line)
  end
end


34
35
36
37
38
39
40
41
# File 'lib/models/base.rb', line 34

def print_table(data)
  hammer.say @headers
  ret = data.each_with_index.map do |item, index|
    item = yield(item, index) if block_given?
    item.to_s
  end.join('')
  hammer.say ret
end

#raw_linesObject



4
5
6
# File 'lib/models/base.rb', line 4

def raw_lines
  hammer.run(command, capture: true).lines
end

#run(*cmds) ⇒ Object



43
44
45
# File 'lib/models/base.rb', line 43

def run(*cmds)
  hammer.run(cmds.join(' '))
end

#search(*keywords) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/models/base.rb', line 23

def search(*keywords)
  keyword, = keywords
  keyword ||= '.'
  regexp = /#{keyword}/i
  ret = load.reject do |item|
    item.regexp = regexp
    regexp.match(item.raw).nil?
  end
  ret
end