aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides/indexer.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 19:55:02 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 20:16:27 +0200
commit80e66cc4d90bf8c15d1a5f6e3152e90147f00772 (patch)
treee7e75464af04f3cf1935b29238dbd7cb2337b0dd /guides/rails_guides/indexer.rb
parent411ccbdab2608c62aabdb320d52cb02d446bb39c (diff)
downloadrails-80e66cc4d90bf8c15d1a5f6e3152e90147f00772.tar.gz
rails-80e66cc4d90bf8c15d1a5f6e3152e90147f00772.tar.bz2
rails-80e66cc4d90bf8c15d1a5f6e3152e90147f00772.zip
normalizes indentation and whitespace across the project
Diffstat (limited to 'guides/rails_guides/indexer.rb')
-rw-r--r--guides/rails_guides/indexer.rb72
1 files changed, 36 insertions, 36 deletions
diff --git a/guides/rails_guides/indexer.rb b/guides/rails_guides/indexer.rb
index 1550ceedac..56df6a5842 100644
--- a/guides/rails_guides/indexer.rb
+++ b/guides/rails_guides/indexer.rb
@@ -17,52 +17,52 @@ module RailsGuides
private
- def process(string, current_level=3, counters=[1])
- s = StringScanner.new(string)
+ def process(string, current_level=3, counters=[1])
+ s = StringScanner.new(string)
- level_hash = {}
+ level_hash = {}
- while !s.eos?
- re = %r{^h(\d)(?:\((#.*?)\))?\s*\.\s*(.*)$}
- s.match?(re)
- if matched = s.matched
- matched =~ re
- level, idx, title = $1.to_i, $2, $3.strip
+ while !s.eos?
+ re = %r{^h(\d)(?:\((#.*?)\))?\s*\.\s*(.*)$}
+ s.match?(re)
+ if matched = s.matched
+ matched =~ re
+ level, idx, title = $1.to_i, $2, $3.strip
- if level < current_level
- # This is needed. Go figure.
- return level_hash
- elsif level == current_level
- index = counters.join(".")
- idx ||= "#" + title_to_idx(title)
+ if level < current_level
+ # This is needed. Go figure.
+ return level_hash
+ elsif level == current_level
+ index = counters.join(".")
+ idx ||= "#" + title_to_idx(title)
- raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{idx}). #{index} #{title}")
+ raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{idx}). #{index} #{title}")
- key = {
- title: title,
- id: idx
- }
- # Recurse
- counters << 1
- level_hash[key] = process(s.post_match, current_level + 1, counters)
- counters.pop
+ key = {
+ title: title,
+ id: idx
+ }
+ # Recurse
+ counters << 1
+ level_hash[key] = process(s.post_match, current_level + 1, counters)
+ counters.pop
- # Increment the current level
- last = counters.pop
- counters << last + 1
+ # Increment the current level
+ last = counters.pop
+ counters << last + 1
+ end
end
+ s.getch
end
- s.getch
+ level_hash
end
- level_hash
- end
- def title_to_idx(title)
- idx = title.strip.parameterize.sub(/^\d+/, "")
- if warnings && idx.blank?
- puts "BLANK ID: please put an explicit ID for section #{title}, as in h5(#my-id)"
+ def title_to_idx(title)
+ idx = title.strip.parameterize.sub(/^\d+/, "")
+ if warnings && idx.blank?
+ puts "BLANK ID: please put an explicit ID for section #{title}, as in h5(#my-id)"
+ end
+ idx
end
- idx
- end
end
end