Class: Ape::Crumbs

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

Instance Method Summary collapse

Constructor Details

#initializeCrumbs

Returns a new instance of Crumbs.



11
12
13
14
# File 'lib/ape/crumbs.rb', line 11

def initialize
  @crumbs = []
  @keep_next = false
end

Instance Method Details

#<<(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/ape/crumbs.rb', line 20

def << data
  if @keep_next
    @crumbs << "> #{data}"
    @keep_next = false
  elsif data =~ /^->/
    @crumbs << "< #{data.gsub(/^.../, '')}"
  elsif data =~ /^<-/
    @keep_next = true
  end
end

#eachObject



31
32
33
# File 'lib/ape/crumbs.rb', line 31

def each
  @crumbs.each { |c| yield c }
end

#grep(pattern) ⇒ Object



16
17
18
# File 'lib/ape/crumbs.rb', line 16

def grep(pattern)
  @crumbs.grep(pattern)
end

#to_sObject



35
36
37
# File 'lib/ape/crumbs.rb', line 35

def to_s
  "  " + @crumbs.join("...\n")
end