Module: Archimate::DataModel::Comparison
- Included in:
- AnyAttribute, AnyElement, Bounds, Color, Concern, Connection, Diagram, Element, Font, LangString, Location, Metadata, Model, ModelingNote, Organization, Property, PropertyDefinition, Relationship, SchemaInfo, Style, ViewNode, Viewpoint
- Defined in:
- lib/archimate/data_model/comparison.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](sym) ⇒ Object
- #dig(*args) ⇒ Object
- #each(&blk) ⇒ Object
- #hash ⇒ Object
- #pretty_print(pp) ⇒ Object
- #to_h ⇒ Object
Class Method Details
.included(base) ⇒ Object
53 54 55 |
# File 'lib/archimate/data_model/comparison.rb', line 53 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/archimate/data_model/comparison.rb', line 11 def ==(other) return true if equal?(other) other.is_a?(self.class) && self.class.comparison_attr_paths.all? do |attr| dig(*attr) == other.dig(*attr) end end |
#[](sym) ⇒ Object
19 20 21 |
# File 'lib/archimate/data_model/comparison.rb', line 19 def [](sym) send(sym) end |
#dig(*args) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/archimate/data_model/comparison.rb', line 23 def dig(*args) return self if args.empty? val = send(args.shift) return val if args.empty? val&.dig(*args) end |
#each(&blk) ⇒ Object
34 35 36 |
# File 'lib/archimate/data_model/comparison.rb', line 34 def each(&blk) self.class.comparison_attr_paths.each(&blk) end |
#hash ⇒ Object
6 7 8 9 |
# File 'lib/archimate/data_model/comparison.rb', line 6 def hash @hash_key ||= self.class.attr_names.reduce(self.class.hash) { |ha, attr| ha ^ send(attr).hash } end |
#pretty_print(pp) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/archimate/data_model/comparison.rb', line 38 def pretty_print(pp) pp.object_address_group(self) do pp.seplist(self.class.comparison_attr_paths, proc { pp.text ',' }) do |attr| column_value = dig(*attr) pp.breakable ' ' pp.group(1) do pp.text Array(attr).map(&:to_s).join(".") pp.text ':' pp.breakable pp.pp column_value end end end end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/archimate/data_model/comparison.rb', line 30 def to_h self.class.attr_names.each_with_object({}) { |i, a| a[i] = send(i) } end |