class Qwik::WikiDB
Constants
- SIGNATURE
Public Class Methods
new(page)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 27 def initialize(page) @page = page @str = nil check_new end
Private Class Methods
encode_line(k, *ar)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 130 def self.encode_line(k, *ar) ar = ar.flatten nar = [] nar << '' # Empty entry. nar << k # The key. nar << ar if ar && ! ar.empty? str = nar.flatten.join(',') return str end
generate_without(str, key)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 111 def self.generate_without(str, key) status = false newar = [] str.each {|line| firstchar = line[0, 1] if SIGNATURE.include?(firstchar) ar = line.chomp.split(firstchar) ar.shift # Drop the first column. k = ar.shift if k && k == key # Do not add the line with the key. status = true # ok. next # Delete the line. end end newar << line } return newar.join, status end
parse(str)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 95 def self.parse(str) array = [] str.each_line {|line| firstchar = line[0, 1] next unless SIGNATURE.include?(firstchar) ar = line.chomp.split(firstchar) ar.shift # Drop the first column. k = ar.shift ar = ar.map {|a| a.strip } v = (firstchar == ':') ? ar.join(':') : ar v.freeze array << [k, v] } return array end
Public Instance Methods
[](key)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 48 def [](key) v = hash[key] return nil if v.nil? return v.dup # dup prevent from destructive method end
add(k, *ar)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 66 def add(k, *ar) ar = ar.flatten @page.add(WikiDB.encode_line(k, ar)+"\n") end
array()
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 33 def array check_new return @array.dup # dup prevent from destructive method end
each() { |k, v| ... }
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 58 def each array.each {|k, v| k = k.dup # unfreeze v = v.dup # dup prevent from destructive method yield(k, v) } end
exist?(key)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 54 def exist?(key) return self[key] end
hash()
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 38 def hash check_new return @hash.dup # dup prevent from destructive method end
remove(key)
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 71 def remove(key) return false unless exist?(key) # Return if the key is not exist. str = @page.load newstr, status = WikiDB.generate_without(str, key) # @page.store(newstr, str.md5hex) # FIXME: Check collision. @page.store(newstr) # FIXME: Store should check the collision. return status end
rev_hash()
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 43 def rev_hash check_new return @rev_hash.dup # dup prevent from destructive method end
Private Instance Methods
check_new()
click to toggle source
# File vendor/qwik/lib/qwik/page-wikidb.rb, line 82 def check_new str = @page.load return if str == @str # Do nothing. @str = str @array = WikiDB.parse(@str) @hash = @array.to_hash @rev_hash = @hash.invert return nil end