Class: SiSU_AO_Hash::ObjectDigest
- Inherits:
-
Object
- Object
- SiSU_AO_Hash::ObjectDigest
- Defined in:
- lib/sisu/ao_hash_digest.rb
Instance Method Summary collapse
-
#endnote_digest(data) ⇒ Object
use md5 or to create hash of each ao object including ocn, & add into to each ao object.
-
#initialize(md, data, env = nil) ⇒ ObjectDigest
constructor
A new instance of ObjectDigest.
- #object_digest ⇒ Object
-
#stamped(t_o, hash_class) ⇒ Object
decide what hash information is most useful, is compromise necessary?.
-
#strip_clean_extra_spaces(s) ⇒ Object
KEEP intact.
Constructor Details
#initialize(md, data, env = nil) ⇒ ObjectDigest
Returns a new instance of ObjectDigest.
58 59 60 61 |
# File 'lib/sisu/ao_hash_digest.rb', line 58 def initialize(md,data,env=nil) @md,@data,@env=md,data,env @env ||=SiSU_Env::InfoEnv.new(@md.fns,@md) end |
Instance Method Details
#endnote_digest(data) ⇒ Object
use md5 or to create hash of each ao object including ocn, & add into to each ao object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/sisu/ao_hash_digest.rb', line 103 def endnote_digest(data) data.each.map do |en_plus| case en_plus when /#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ if en_plus =~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/ t_o_txt,en_open,en_txt,en_close= /(.*?)(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m. match(en_plus)[1..4] stripped_en=SiSU_TextRepresentation::Alter.new(en_txt).strip_clean_of_markup digest_en_strip=case @env.digest(@md.opt).type when :sha512 Digest::SHA512.hexdigest(stripped_en) when :sha256 Digest::SHA256.hexdigest(stripped_en) when :md5 Digest::MD5.hexdigest(stripped_en) else Digest::SHA256.hexdigest(stripped_en) end t_o_txt + en_open + en_txt + Mx[:id_o] + digest_en_strip + Mx[:id_c] + en_close else STDERR.puts "Error Exception - problem encountered with:\n#{en_plus}" #arbitrary exception, tidy up end else en_plus end end.join end |
#object_digest ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sisu/ao_hash_digest.rb', line 62 def object_digest # 1. clean/stripped text without any markup, paragraph, headings etc. without endnotes # 2. endnotes clean/stripped text digest only (there may be several endnotes within a paragraph) # 3. whole object, text with markup and any endnotes, (question: with or without the endnote digests??? presumption better without, [however may be easier to check with?]) # [digests should not include other digests] data=@data.compact @tuned_file=[] sha_ =@env.digest(@md.opt).type begin sha_ ? (require 'digest/sha2') : (require 'digest/md5') rescue LoadError SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error(sha_ + ' NOT FOUND') end data.each do |t_o| unless t_o.obj.is_a?(Array) t_o.obj=t_o.obj.strip end if (t_o.of !=:structure \ && t_o.of !=:comment \ && t_o.of !=:layout) \ && t_o.ocn.is_a?(Fixnum) case sha_ when :sha512 for hash_class in [ Digest::SHA512 ] @tuned_file << stamped(t_o,hash_class) end when :sha256 for hash_class in [ Digest::SHA256 ] @tuned_file << stamped(t_o,hash_class) end when :md5 for hash_class in [ Digest::MD5 ] @tuned_file << stamped(t_o,hash_class) end end else @tuned_file << t_o unless t_o.nil? end end @tuned_file=@tuned_file.flatten #use md5 or to create hash of each ao object including ocn, & add into to each ao object end |
#stamped(t_o, hash_class) ⇒ Object
decide what hash information is most useful, is compromise necessary?
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/sisu/ao_hash_digest.rb', line 135 def stamped(t_o,hash_class) #decide what hash information is most useful, is compromise necessary? t_o.obj=SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_extra_spaces #SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_markup #check #SiSU_TextRepresentation::Alter.new(t_o).semi_revert_markup #check #SiSU_TextRepresentation::ModifiedTextPlusHashDigest.new(@md,t_o).composite.dgst #check unless t_o.is==:code case t_o.obj when /#{Mx[:en_a_o]}[\d*+]+\s+.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\d+\s+.+?#{Mx[:en_b_c]}/m en_and_t_o_digest=[] t_o.obj=t_o.obj. gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,' \1') #watch t_o_plus_en=t_o.obj. scan(/.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m) t_o_tail=if t_o.obj =~/(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+([\s\S]+)/m /(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+.*/m.match(t_o.obj)[1] else '' end t_o_plus_en << t_o_tail en_and_t_o_digest << endnote_digest(t_o_plus_en) en_and_t_o_digest.join(' ') else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? end else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? end t_o #KEEP intact end |
#strip_clean_extra_spaces(s) ⇒ Object
KEEP intact
161 162 163 164 165 166 167 168 169 |
# File 'lib/sisu/ao_hash_digest.rb', line 161 def strip_clean_extra_spaces(s) # ao output tuned s=s.dup s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ s=s.gsub(/ [ ]+/,' '). gsub(/^ [ ]+/,''). gsub(/ [ ]+$/,''). gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2'). gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2') end |