Class: FoxDisplayer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text_field) ⇒ FoxDisplayer

Returns a new instance of FoxDisplayer.



4
5
6
7
8
9
10
11
12
# File 'lib/FoxDisplayer.rb', line 4

def initialize(text_field)
  @text_field = text_field
  @formatter = FoxTextFormatter.new(70, "") do |arg, style|
    startpos = @str.size
    @str << arg
    @formats.push [startpos, arg.size, style]
  end
  @reader = nil
end

Instance Attribute Details

#readerObject

Returns the value of attribute reader.



2
3
4
# File 'lib/FoxDisplayer.rb', line 2

def reader
  @reader
end

Instance Method Details

#display_class_info(klass) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/FoxDisplayer.rb', line 79

def display_class_info(klass)
  init_text
  superclass = klass.superclass_string
  if superclass
    superclass = " < " + superclass
  else
    superclass = ""
  end
  @formatter.draw_line(klass.display_name + ": " + klass.full_name + superclass)
  display_flow(klass.comment)
  @formatter.draw_line

  unless klass.includes.empty?
    @formatter.blankline
    @formatter.display_heading("Includes:", 2, "")
    incs = []
    klass.includes.each do |inc|
      inc_desc = @reader.find_class_by_name(inc.name)
      if inc_desc
        str = inc.name + "("
        str << inc_desc.instance_methods.map{|m| m.name}.join(", ")
        str << ")"
        incs << str
      else
        incs << inc.name
      end
    end
    @formatter.wrap(incs.sort.join(', '))
  end

  unless klass.constants.empty?
    @formatter.blankline
    @formatter.display_heading("Constants:", 2, "")
    len = 0
    klass.constants.each { |c| len = c.name.length if c.name.length > len }
    len += 2
    klass.constants.each do |c|
      @formatter.wrap(c.value, @formatter.indent+((c.name+":").ljust(len)))
    end
  end

  unless klass.class_methods.empty?
    @formatter.blankline
    @formatter.display_heading("Class methods:", 2, "")
    @formatter.wrap(klass.class_methods.map{|m| m.name}.sort.join(', '))
  end

  unless klass.instance_methods.empty?
    @formatter.blankline
    @formatter.display_heading("Instance methods:", 2, "")
    @formatter.wrap(klass.instance_methods.map{|m| m.name}.sort.join(', '))
  end

  unless klass.attributes.empty?
    @formatter.blankline
    @formatter.wrap("Attributes:", "")
    @formatter.wrap(klass.attributes.map{|a| a.name}.sort.join(', '))
  end

  set_text
end

#display_flow(flow) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/FoxDisplayer.rb', line 141

def display_flow(flow)
  if !flow || flow.empty?
    @formatter.wrap("(no description...)\n")
  else
    @formatter.display_flow(flow)
  end
end

#display_information(message) ⇒ Object



73
74
75
76
77
# File 'lib/FoxDisplayer.rb', line 73

def display_information(message)
  init_text
  display_flow(message)
  set_text
end

#display_method_info(method) ⇒ Object

Display method information



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/FoxDisplayer.rb', line 56

def display_method_info(method)
  init_text
  @formatter.draw_line(method.full_name)
  @formatter.display_params(method)
  @formatter.draw_line
  display_flow(method.comment)

  if method.aliases && !method.aliases.empty?
    @formatter.blankline
    aka = "(also known as "
    aka << method.aliases.map {|a| a.name }.join(", ")
    aka << ")"
    @formatter.wrap(aka)
  end
  set_text
end

#init_textObject



22
23
24
25
# File 'lib/FoxDisplayer.rb', line 22

def init_text
  @str = ""
  @formats = Array.new
end

#no_info_availableObject



18
19
20
# File 'lib/FoxDisplayer.rb', line 18

def no_info_available
  @text_field.text="nothing here, move on!"
end

#set_textObject

Sets a new text, and all styles



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/FoxDisplayer.rb', line 28

def set_text
  @text_field.text = @str
  @formats.each do |start, n, style|
    case style
    when FoxTextFormatter::STYLE_BOLD
      @text_field.changeStyle(start, n, 2)
    when FoxTextFormatter::STYLE_H1
      @text_field.changeStyle(start, n, 3)
    when FoxTextFormatter::STYLE_H2
      @text_field.changeStyle(start, n, 4)
    when FoxTextFormatter::STYLE_H3
      @text_field.changeStyle(start, n, 5)
    when FoxTextFormatter::STYLE_TELETYPE
      @text_field.changeStyle(start, n, 6)
    when FoxTextFormatter::STYLE_CODE
      @text_field.changeStyle(start, n, 7)
    when FoxTextFormatter::STYLE_EMPHASIS
      @text_field.changeStyle(start, n, 8)
    when FoxTextFormatter::STYLE_CLASS
      @text_field.changeStyle(start, n, 9)
    else
      @text_field.changeStyle(start, n, 1)
    end

  end
end

#width=(newWidth) ⇒ Object



14
15
16
# File 'lib/FoxDisplayer.rb', line 14

def width=(newWidth)
  @formatter.width = newWidth
end