Skip to content

Instantly share code, notes, and snippets.

@CapSens-SM
Last active May 9, 2020 14:59
Show Gist options
  • Save CapSens-SM/e31033488ac4ef0fe399f54eee96bf56 to your computer and use it in GitHub Desktop.
Save CapSens-SM/e31033488ac4ef0fe399f54eee96bf56 to your computer and use it in GitHub Desktop.
class CustomerDecorator < Draper::Decorator
delegate_all
# [ other decorator logic here ... ]
def state_completition_in_percent
customer_state_index = Customer.state.values.index(state).to_f + 1
return 100 if state == :terminated
total_states_count_without_terminated_state = Customer.state.values.length - 1
completion = customer_state_index / total_states_count_without_terminated_state
(completion * 100).round(0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment