Module: CWG::Element

Included in:
CwStream
Defined in:
/Users/martyn/cw/cw_clone/lib/cw/element.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) check_last_element_success(match, first, last)



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

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

- (Object) count



65
66
67
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 65

def count
  @last_element - @first_element
end

- (Object) element(type)



7
8
9
10
11
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 7

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

- (Object) get_first



55
56
57
58
59
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 55

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

- (Object) get_last



61
62
63
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 61

def get_last
  @last_element - 1
end

- (Object) inc_first_element



73
74
75
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 73

def inc_first_element
  @first_element += 1
end

- (Object) inc_last_element



69
70
71
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 69

def inc_last_element
  @last_element += 1
end

- (Object) match_first_active_element(match)



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

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

- (Object) match_last_active_element(match)



32
33
34
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 32

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

- (Object) process_last_active_element(match)



36
37
38
39
40
# File '/Users/martyn/cw/cw_clone/lib/cw/element.rb', line 36

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