Module: ContentData
- Defined in:
- lib/content_data.rb,
lib/content_data/version.rb,
lib/content_data/content_data.rb,
lib/content_data/dynamic_content_data.rb
Overview
Data structure for an abstract layer over files. Each binary sequence is a content, each file is content instance.
Defined Under Namespace
Classes: ContentData, DynamicContentData
Constant Summary collapse
- VERSION =
"1.1.0"
Class Method Summary collapse
-
.intersect(a, b) ⇒ Object
returns the common content in both a and b.
-
.merge(a, b) ⇒ Object
merges content data a and content data b to a new content data and returns it.
- .merge_override_b(a, b) ⇒ Object
-
.remove(a, b) ⇒ Object
B - A : Remove contents of A from B and return the new content data.
- .remove_directory(content_data, dir_to_remove, server_to_remove) ⇒ Object
-
.remove_instances(a, b) ⇒ Object
B - A : Remove instances of A content from B content data B and return the new content data.
Class Method Details
.intersect(a, b) ⇒ Object
returns the common content in both a and b
605 606 607 608 609 610 |
# File 'lib/content_data/content_data.rb', line 605 def self.intersect(a, b) return nil if a.nil? return nil if b.nil? b_minus_a = remove(a, b) b_minus_b_minus_a = remove(b_minus_a, b) end |
.merge(a, b) ⇒ Object
merges content data a and content data b to a new content data and returns it.
502 503 504 505 506 507 508 509 510 511 |
# File 'lib/content_data/content_data.rb', line 502 def self.merge(a, b) return ContentData.new(a) if b.nil? return ContentData.new(b) if a.nil? c = ContentData.new(b) # Add A instances to content data c a.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path| c.add_instance(checksum, size, server, path, instance_mod_time) } c end |
.merge_override_b(a, b) ⇒ Object
513 514 515 516 517 518 519 520 521 |
# File 'lib/content_data/content_data.rb', line 513 def self.merge_override_b(a, b) return ContentData.new(a) if b.nil? return ContentData.new(b) if a.nil? # Add A instances to content data B a.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path| b.add_instance(checksum, size, server, path, instance_mod_time) } b end |
.remove(a, b) ⇒ Object
B - A : Remove contents of A from B and return the new content data. instances are ignored e.g A db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
B db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
Instance_4
Content_3 ->
Instance_5
B-A db:
Content_3 ->
Instance_5
547 548 549 550 551 552 553 554 555 556 |
# File 'lib/content_data/content_data.rb', line 547 def self.remove(a, b) return nil if b.nil? return ContentData.new(b) if a.nil? c = ContentData.new(b) # create new cloned content C from B # remove contents of A from newly cloned content A a.each_content { |checksum, size, content_mod_time| c.remove_content(checksum) } c end |
.remove_directory(content_data, dir_to_remove, server_to_remove) ⇒ Object
592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/content_data/content_data.rb', line 592 def self.remove_directory(content_data, dir_to_remove, server_to_remove) return nil if content_data.nil? result_content_data = ContentData.new() content_data.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path| # Keep instance if path is not of server to remove or path does not include dir to remove if (server_to_remove!=server) or (path.scan(dir_to_remove).size == 0) result_content_data.add_instance(checksum.clone, size, server, path.clone, instance_mod_time) end } result_content_data end |
.remove_instances(a, b) ⇒ Object
B - A : Remove instances of A content from B content data B and return the new content data. If all instances are removed then the content record itself will be removed e.g A db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
B db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
Instance_4
B-A db:
Content_2 ->
Instance_4
580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/content_data/content_data.rb', line 580 def self.remove_instances(a, b) return nil if b.nil? return ContentData.new(b) if a.nil? c = ContentData.new(b) # create new cloned content C from B # remove contents of A from newly cloned content A a.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path| location = [server, path] c.remove_instance(location, checksum) } c end |