Module: MongoTools

Defined in:
lib/md5.rb

Instance Method Summary collapse

Instance Method Details

#calc_md5(md_string) ⇒ Object



36
37
38
39
# File 'lib/md5.rb', line 36

def calc_md5(md_string)
    ret=Digest::MD5.hexdigest(md_string)
    ret
end

#concat_string(field_names, start_with) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/md5.rb', line 10

def concat_string(field_names,start_with)
    retString = start_with
    field_names.each do |field|
        field_content = read_attribute(field).inspect
            retString = retString + field_content
    end
retString
end

#find_or_create_with_md5(elements) ⇒ Object

aufter that method the element exists in al cases. it returns true if the item has to be created otherwise false



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/md5.rb', line 23

def find_or_create_with_md5(elements)
    md5_string =  md5_create(elements)
    if  !self.class.where(md5: md5_string).exists?
        self.md5 = md5_string
        self.save!
        return true
    else
        return false
    end

end

#md5_create(field_names) ⇒ Object



5
6
7
# File 'lib/md5.rb', line 5

def md5_create(field_names)
   calc_md5(concat_string(field_names,"")) 
end