Module: Ace::Bundle::Atoms::LineCounter
- Defined in:
- lib/ace/bundle/atoms/line_counter.rb
Overview
Pure function to count lines in content Follows ATOM architecture: no side effects, single purpose
Class Method Summary collapse
-
.count(content) ⇒ Integer
Count the number of lines in content.
Class Method Details
.count(content) ⇒ Integer
Count the number of lines in content
25 26 27 28 29 30 31 32 |
# File 'lib/ace/bundle/atoms/line_counter.rb', line 25 def count(content) return 0 if content.nil? || content.empty? # Count actual lines of content # "a\nb\nc" => 3 lines # "a\nb\n" => 2 lines (trailing newline doesn't add a line) content.count("\n") + (content.end_with?("\n") ? 0 : 1) end |