Skip to content

Commit

Permalink
Refactor: Extract method: tier.includes?(value)
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Jan 3, 2017
1 parent c5ff669 commit b5d826a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions app/models/chargeback_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ def fixed?
def find_rate(value)
fixed_rate = 0.0
variable_rate = 0.0
tier_found, = chargeback_tiers.select do |tier|
tier.starts_with_zero? && value.zero? ||
value > (rate_adjustment * tier.start) && value <= (rate_adjustment * tier.finish)
end
tier_found = chargeback_tiers.detect { |tier| tier.includes?(value / rate_adjustment) }
unless tier_found.nil?
fixed_rate = tier_found.fixed_rate
variable_rate = tier_found.variable_rate
Expand Down
4 changes: 4 additions & 0 deletions app/models/chargeback_tier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def self.to_float(s)
end
end

def includes?(value)
starts_with_zero? && value.zero? || value > start && value <= finish
end

def starts_with_zero?
start.zero?
end
Expand Down

0 comments on commit b5d826a

Please sign in to comment.