Class: Fried::Schema::Compare

Inherits:
Object
  • Object
show all
Includes:
Typings
Defined in:
lib/fried/schema/compare.rb

Overview

Compares two Struct objects, used for sorting and equality

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompare

Returns a new instance of Compare.



14
15
16
# File 'lib/fried/schema/compare.rb', line 14

def initialize
  self.get_attribute = GetAttribute.new
end

Instance Attribute Details

#get_attributeObject

Returns the value of attribute get_attribute.



12
13
14
# File 'lib/fried/schema/compare.rb', line 12

def get_attribute
  @get_attribute
end

Class Method Details

.buildObject



18
19
20
21
22
# File 'lib/fried/schema/compare.rb', line 18

def self.build
  new.tap do |instance|
    instance.get_attribute = GetAttribute.build
  end
end

.call(schema, struct, other) ⇒ Object



24
25
26
27
# File 'lib/fried/schema/compare.rb', line 24

def self.call(schema, struct, other)
  instance = build
  instance.(schema, struct, other)
end

Instance Method Details

#call(schema, struct, other) ⇒ Integer?

Returns like ‘<=>` sign.

Parameters:

Returns:

  • (Integer, nil)

    like ‘<=>` sign



33
34
35
36
37
38
39
# File 'lib/fried/schema/compare.rb', line 33

def call(schema, struct, other)
  return nil unless struct.class == other.class
  return nil unless Is[Struct].valid?(struct)
  return nil unless Is[Struct].valid?(other)

  compare(schema, struct, other)
end