Class: Cog::Helpers::SourceInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/cog/helpers/cascading_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SourceInfo

Returns a new instance of SourceInfo.



9
10
11
12
13
# File 'lib/cog/helpers/cascading_set.rb', line 9

def initialize(name)
  @info = []
  @types = []
  @name = name
end

Instance Attribute Details

#nameObject (readonly)



6
7
8
# File 'lib/cog/helpers/cascading_set.rb', line 6

def name
  @name
end

#pathObject



7
8
9
# File 'lib/cog/helpers/cascading_set.rb', line 7

def path
  @path
end

Instance Method Details

#<=>(other) ⇒ Object



48
49
50
# File 'lib/cog/helpers/cascading_set.rb', line 48

def <=>(other)
  (@path || @name) <=> (other.path || other.name)
end

#add_source(source, type = nil) ⇒ Object



15
16
17
18
19
# File 'lib/cog/helpers/cascading_set.rb', line 15

def add_source(source, type=nil)
  type ||= source
  @info << source
  @types << type
end

#override_s(width = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/cog/helpers/cascading_set.rb', line 38

def override_s(width=nil)
  colorless = "[#{@info.join ' < '}]"
  if width
    x = @info.zip(@types).collect {|source, type| style source, type}
    "[#{x.join ' < '}]" + " " * (width - colorless.length)
  else
    colorless
  end
end

#style(text, type) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cog/helpers/cascading_set.rb', line 21

def style(text, type)
  case type
  when :built_in
    text.color :cyan
  when :gem
    text.color :blue
  when :user
    text.color :green
  when :plugin
    text.color :yellow
  when :project
    text.color(:white).bright
  else
    text
  end
end

#to_s(override_column_width) ⇒ Object



52
53
54
# File 'lib/cog/helpers/cascading_set.rb', line 52

def to_s(override_column_width)
  "#{override_s override_column_width} #{style @path || @name, @types.last}"
end