Module: HashId
- Included in:
- Elibri::ONIX::Release_3_0::Collection, Elibri::ONIX::Release_3_0::Imprint, Elibri::ONIX::Release_3_0::Measure, Elibri::ONIX::Release_3_0::ONIXMessage, Elibri::ONIX::Release_3_0::Price, Elibri::ONIX::Release_3_0::ProductIdentifier, Elibri::ONIX::Release_3_0::PublishingDate, Elibri::ONIX::Release_3_0::RelatedProduct, Elibri::ONIX::Release_3_0::SalesRestriction, Elibri::ONIX::Release_3_0::StockQuantityCoded, Elibri::ONIX::Release_3_0::Subject, Elibri::ONIX::Release_3_0::Supplier, Elibri::ONIX::Release_3_0::SupplierIdentifier, Elibri::ONIX::Release_3_0::SupplyDetail, Elibri::ONIX::Release_3_0::TitleDetail, Elibri::ONIX::Release_3_0::TitleElement
- Defined in:
- lib/elibri_onix/hash_id.rb
Constant Summary collapse
- SKIPPED_ATTRIBS =
["@opts", "@default_namespace", "@instance"]
- SKIPPED_2 =
["@id", "@id_before_type_cast"]
Instance Method Summary collapse
Instance Method Details
#calculate_hash(object) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elibri_onix/hash_id.rb', line 10 def calculate_hash(object) result = [] if object.is_a? Array object.each { |x| result << calculate_hash(x) } else vars = [] if object.class.to_s.include? "Elibri::ONIX" vars += object.class::ATTRIBUTES vars += object.class::RELATIONS end vars = object.instance_variables if vars.blank? vars.each do |attrib| next if SKIPPED_ATTRIBS.include? attrib next if SKIPPED_2.include? attrib attrib = attrib.to_s.gsub("@", "").to_sym if attrib.is_a?(String) if object.send(attrib).is_a? Array result << calculate_hash(object.send(attrib)) elsif object.send(attrib).is_a?(String) || object.send(attrib).is_a?(Numeric) || object.send(attrib).is_a?(Fixnum) || object.send(attrib).is_a?(Symbol) result << object.send(attrib) else result << calculate_hash(object.send(attrib)) end end end return Digest::SHA1.hexdigest(result.join("-")) end |
#eid ⇒ Object
6 7 8 |
# File 'lib/elibri_onix/hash_id.rb', line 6 def eid calculate_hash(self) end |