Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/snibbets/array.rb
Instance Method Summary collapse
- #blocks ⇒ Object
- #notes ⇒ Object
- #remove_leading_empty_elements ⇒ Object
- #remove_trailing_empty_elements ⇒ Object
- #strip_empty ⇒ Object
- #strip_empty! ⇒ Object
Instance Method Details
#blocks ⇒ Object
3 4 5 |
# File 'lib/snibbets/array.rb', line 3 def blocks select { |el| el =~ /^<block\d+>$/ }.count end |
#notes ⇒ Object
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_elements ⇒ Object
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_elements ⇒ Object
35 36 37 |
# File 'lib/snibbets/array.rb', line 35 def remove_trailing_empty_elements reverse.remove_leading_empty_elements.reverse end |
#strip_empty ⇒ Object
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 |