We were displaying dates in two different formats in the same component, leading to strange hacks like manually calling the `call` method or not being able to use `render_inline` in the tests. Since we're going to reuse one of these formats outside the budgets section, we're splitting the component. We're also removing the mentioned hacks.
18 lines
320 B
Ruby
18 lines
320 B
Ruby
class Admin::Budgets::DurationInWordsComponent < ApplicationComponent
|
|
attr_reader :durable
|
|
|
|
def initialize(durable)
|
|
@durable = durable
|
|
end
|
|
|
|
def render?
|
|
durable.starts_at && durable.ends_at
|
|
end
|
|
|
|
private
|
|
|
|
def duration
|
|
distance_of_time_in_words(durable.starts_at, durable.ends_at)
|
|
end
|
|
end
|