Module: Mizuho::Utils

Extended by:
Utils
Included in:
IdMap, Utils
Defined in:
lib/mizuho/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



27
28
29
30
31
32
33
# 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

Instance Method Details

#chapter_to_int_array(chapter) ⇒ Object



48
49
50
# 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) ⇒ Object

Given a title with a chapter number, e.g. “6.1 Installation using tarball”, splits the two up.



37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# 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