Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ruby/engine/lib/rbbb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Error < StandardError; end
class InvalidConfiguration < Error; end
class InvalidMoney < Error; end
class InvalidState < Error; end
class UnsupportedFeature < Error; end
end

require_relative "rbbb/money"
Expand Down
27 changes: 27 additions & 0 deletions ruby/engine/lib/rbbb/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Configuration
:increment_schedule, :bid_ladder, :opens_at, :closes_at, :extension

def self.from_h(attributes)
unless attributes.respond_to?(:transform_keys)
raise InvalidConfiguration, "configuration must be an object"
end

values = attributes.transform_keys(&:to_s)
new(
currency: values.fetch("currency"),
Expand Down Expand Up @@ -54,6 +58,29 @@ def increment_for(minor_units)
increment_schedule.increment_for(minor_units)
end

def ==(other)
other.is_a?(Configuration) && equality_key == other.equality_key
end
alias eql? ==

def hash
[self.class, equality_key].hash
end

protected

def equality_key
[
currency,
opening_minor_units,
reserve_minor_units,
increment_schedule.to_a,
Timestamp.dump(opens_at),
Timestamp.dump(closes_at),
extension
]
end

private

def parse_timestamp(value, field)
Expand Down
23 changes: 23 additions & 0 deletions ruby/engine/lib/rbbb/decision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,28 @@ def accepted?
def rejected?
!accepted?
end

def transition_event
events.find do |event|
event.privileged? && Engine::STATE_TRANSITION_EVENTS.include?(event.type)
end
end

def public_events
events.select(&:public?)
end

def privileged_events
events.select(&:privileged?)
end

def ==(other)
other.is_a?(Decision) && events == other.events && rejection == other.rejection
end
alias eql? ==

def hash
[self.class, events, rejection].hash
end
end
end
Loading