Class: Array

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

Instance Method Summary collapse

Instance Method Details

#find_extra_kids(hash, kids = []) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/hum/array.rb', line 61

def find_extra_kids(hash, kids = [])
  
  #find the parent
  parent = self.find_line(hash[:parent])
  
  #target the next line
  next_line = hash[:parent] + 1

  #find the next line
  found = self.find_line(next_line)
  
  until found.nil? or next_line == hash[:line] or parent[:tab] == found[:tab]
    
    #collect it if not a mixin
    if !found[:exclude]
      kids << found[:line]
    end
  
    #increment
    next_line += 1
    
    #find the next one
    found = self.find_line(next_line)
  end
  
  kids
end

#find_kids(hash, kids = []) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hum/array.rb', line 35

def find_kids(hash, kids = [])
  
  #get the next line number
  next_line = hash[:line] + 1
  
  #find the next one
  found = self.find_line(next_line)
  
  until found.nil? or hash[:tab] >= found[:tab]
    
    #collect it if not a mixin
    if !found[:exclude]
      kids << found[:line]
    end
    
    #increment
    next_line += 1
    
    #find the next one
    found = self.find_line(next_line)
  end
  
  #return all kids
  kids
end

#find_line(target, found = nil) ⇒ Object

find a specific line



3
4
5
6
7
8
9
10
# File 'lib/hum/array.rb', line 3

def find_line(target, found = nil)
  self.each do |css| 
    if css[:line] == target
      found = css
    end
  end
  found
end

#find_parent(of_this_hash, found = nil) ⇒ Object

find the parent of a line



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hum/array.rb', line 13

def find_parent(of_this_hash, found = nil)
  
  #target the line number
  line_number = of_this_hash[:line] - 1
  
  #find the line
  found = self.find_line(line_number)

  #finds the direct parent with the correct tab
  until found.nil? or found[:tab] == of_this_hash[:tab] - 1
    
    #go up the tree
    line_number -= 1
    
    #find the line
    found = self.find_line(line_number)
  end

  #return the right parent line
  found[:line]
end