Class: ReFe::OutputPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/refe/searcher.rb

Constant Summary collapse

LINE_MAX =
60

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all, short, line) ⇒ OutputPolicy

Returns a new instance of OutputPolicy.



178
179
180
181
182
# File 'lib/refe/searcher.rb', line 178

def initialize( all, short, line )
  @all = all
  @short = short
  @line = line
end

Class Method Details

.new2(opts) ⇒ Object



174
175
176
# File 'lib/refe/searcher.rb', line 174

def OutputPolicy.new2( opts )
  new(opts['all'], opts['short'], opts['line'])
end

Instance Method Details

#packed_print(list) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/refe/searcher.rb', line 202

def packed_print( list )
  return if list.empty?
  len = 0
  sep = ''
  list.sort.each do |word|
    if len != 0 and (len + sep.size + word.size > LINE_MAX)
      sep = "\n"; len = 0
    end
    print sep, word; len += sep.size + word.size
    sep = ' '
  end
  puts
end


190
191
192
193
194
195
196
197
198
# File 'lib/refe/searcher.rb', line 190

def print_names( list )
  if @line
    list.sort.each do |i|
      puts i
    end
  else
    packed_print list
  end
end

#should_print_content?(results) ⇒ Boolean

Returns:

  • (Boolean)


184
185
186
187
188
# File 'lib/refe/searcher.rb', line 184

def should_print_content?( results )
  return false if @short
  return true if @all
  results.size == 1
end