module Mizuho::Utils
Public Class Methods
included(klass)
click to toggle source
# File lib/mizuho/utils.rb, line 27 def self.included(klass) # When included into another class, make sure that Utils # methods are made private. public_instance_methods(false).each do |method_name| klass.send(:private, method_name) end end
Public Instance Methods
chapter_to_int_array(chapter)
click to toggle source
# File lib/mizuho/utils.rb, line 48 def chapter_to_int_array(chapter) return chapter.split('.').map { |x| x.to_i } end
extract_chapter(title)
click to toggle source
Given a title with a chapter number, e.g. “6.1 Installation using tarball”, splits the two up.
# File lib/mizuho/utils.rb, line 37 def extract_chapter(title) title =~ /^((\d+\.)*) (.+)$/ chapter = $1 pure_title = $3 if !chapter.nil? && !chapter.empty? && pure_title && !pure_title.empty? return [chapter, pure_title] else return nil end end
title_to_docid(title)
click to toggle source
# File lib/mizuho/utils.rb, line 52 def title_to_docid(title) chapter, pure_title = extract_chapter(title) p title numbers = chapter_to_int_array(chapter) result = 0 bit_offset = 0 numbers.each do |num| result = result | (num << bit_offset) bit_offset += 5 end return result end