Class: Array

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

Instance Method Summary collapse

Instance Method Details

#blocksObject



3
4
5
# File 'lib/snibbets/array.rb', line 3

def blocks
  select { |el| el =~ /^<block\d+>$/ }.count
end

#notesObject



7
8
9
# File 'lib/snibbets/array.rb', line 7

def notes
  select { |el| el !~ /^<block\d+>$/ && el !~ /^```/ && !el.strip.empty? }.count
end

#remove_leading_empty_elementsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/snibbets/array.rb', line 19

def remove_leading_empty_elements
  output = []

  in_leader = true
  each do |line|
    if (line.strip.empty?) && in_leader
      next
    else
      in_leader = false
      output << line
    end
  end

  output
end

#remove_trailing_empty_elementsObject



35
36
37
# File 'lib/snibbets/array.rb', line 35

def remove_trailing_empty_elements
  reverse.remove_leading_empty_elements.reverse
end

#strip_emptyObject



11
12
13
# File 'lib/snibbets/array.rb', line 11

def strip_empty
  remove_leading_empty_elements.remove_trailing_empty_elements
end

#strip_empty!Object



15
16
17
# File 'lib/snibbets/array.rb', line 15

def strip_empty!
  replace strip_empty
end