Class: Cheatorious::Writer::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/cheatorious/writer/text.rb

Instance Method Summary collapse

Constructor Details

#initializeText

Returns a new instance of Text.



6
7
8
9
10
11
12
13
# File 'lib/cheatorious/writer/text.rb', line 6

def initialize
  @section_stack = []
  @result        = ""
  @query         = nil
  @options       = {}
  @color         = :yellow
  @add_empty_line = true
end

Instance Method Details

#entry(name, *values) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cheatorious/writer/text.rb', line 53

def entry(name, *values)
  value_text = values.join(", ")
  if @options['reverse']
    value_text = paint(value_text,@query) if @query
  elsif !@options['section']
    name = paint(name,@query) if @query
  end
  e = "#{indentation(" ")}   #{name} " + "=> ".foreground(:blue)
  e << value_text
  line e
end


35
36
37
38
39
# File 'lib/cheatorious/writer/text.rb', line 35

def footer
  line
  line "-" * 80
  line "generated by Cheatorious (https://github.com/lfcipriani/cheatorious)"
end

#header(name, author = "", version = "", description = "") ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cheatorious/writer/text.rb', line 15

def header(name, author = "", version = "", description = "")
  line "-" * 80
  line "#{name} (#{version})"
  line
  line "Author     : #{author[0]} (#{author[1]})"
  line "Description: #{description}"
  line "-" * 80
  line
end

#resultObject



65
66
67
# File 'lib/cheatorious/writer/text.rb', line 65

def result
  @result
end

#search_header(query, results_count, options) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/cheatorious/writer/text.rb', line 25

def search_header(query, results_count, options)
  @query = query
  @options = options
  search_type = (options.keys - ["writer"]).join(", ")
  search_type += " " if search_type.size > 0
  line "Your #{search_type}search for '#{query.dup.foreground(@color)}' returned #{results_count} #{results_count > 1 ? "results" : "result"}:" if results_count != 0
  line "Your #{search_type}search for '#{query.dup.foreground(@color)}' doesn't returned any result. Try with another keyword." if results_count == 0
  line
end

#section_endObject



48
49
50
51
# File 'lib/cheatorious/writer/text.rb', line 48

def section_end
  @section_stack.pop
  line
end

#section_start(section) ⇒ Object



41
42
43
44
45
46
# File 'lib/cheatorious/writer/text.rb', line 41

def section_start(section)
  @section_stack.push(section)
  section = paint(section,@query) if @query && @options['section']
  line
  line indentation(" ") + "#".foreground(:red) + " #{section} "+ "#".foreground(:red)
end