Module: CW::Element

Included in:
Stream
Defined in:
lib/cw/element.rb

Instance Method Summary collapse

Instance Method Details

#check_last_element_success(match, first, last) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cw/element.rb', line 41

def check_last_element_success(match, first, last)
  found = false
  last.downto(first) do |element|
    if found
      @success[element] = false unless @success[element]
    elsif((@stream[element] == match) && (! @success[element]))
      @success[element], found = true, true
    else
      @success[first] = false
    end
  end
end

#countObject



64
65
66
# File 'lib/cw/element.rb', line 64

def count
  @last_element - @first_element
end

#element(type) ⇒ Object



6
7
8
9
10
# File 'lib/cw/element.rb', line 6

def element type
  return @last_element - 1 if type == :last
  first = @last_element - @active_region - 1
  first < 0 ? 0 : first
end

#get_firstObject



54
55
56
57
58
# File 'lib/cw/element.rb', line 54

def get_first
  first = @last_element - @active_region - 1
  first = 0 if(first < 0)
  first
end

#get_lastObject



60
61
62
# File 'lib/cw/element.rb', line 60

def get_last
  @last_element - 1
end

#inc_first_elementObject



72
73
74
# File 'lib/cw/element.rb', line 72

def inc_first_element
  @first_element += 1
end

#inc_last_elementObject



68
69
70
# File 'lib/cw/element.rb', line 68

def inc_last_element
  @last_element += 1
end

#match_first_active_element(match) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cw/element.rb', line 12

def match_first_active_element match
  if ! stream_empty?
    found = false
    first = element(:first)
    first.upto element(:last) do |ele|
      if found
        first.upto found - 1 do |failed|
          @success[failed] = false # unless @success[ele]
        end
        break
      elsif((@stream[ele] == match) && (! @success[ele]))
        @success[ele], found = true, ele
      else
        @success[first] = false
      end
    end
  end
end

#match_last_active_element(match) ⇒ Object



31
32
33
# File 'lib/cw/element.rb', line 31

def match_last_active_element(match)
  process_last_active_element(match) unless stream_empty?
end

#process_last_active_element(match) ⇒ Object



35
36
37
38
39
# File 'lib/cw/element.rb', line 35

def process_last_active_element(match)
  first = get_first
  last  = get_last
  check_last_element_success(match, first, last)
end