Class: Reading::Row::SpansSubattribute

Inherits:
Object
  • Object
show all
Defined in:
lib/reading/attribute/experiences/spans_subattribute.rb

Instance Method Summary collapse

Constructor Details

#initialize(date_entry:, dates_finished:, date_index:, variant_index:, columns:, config:) ⇒ SpansSubattribute

Returns a new instance of SpansSubattribute.

Parameters:

  • date_entry (String)

    the entry in Dates Started.

  • dates_finished (Array<String>)

    the entries in Dates Finished.

  • date_index (Integer)

    the index of the entry.

  • variant_index (Integer)

    the variant index, for getting length for default amount.

  • columns (Array<String>)
  • config (Hash)


14
15
16
17
18
19
20
21
# File 'lib/reading/attribute/experiences/spans_subattribute.rb', line 14

def initialize(date_entry:, dates_finished:, date_index:, variant_index:, columns:, config:)
  @date_entry = date_entry
  @dates_finished = dates_finished
  @date_index = date_index
  @variant_index = variant_index
  @columns = columns
  @config = config
end

Instance Method Details

#parseObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/reading/attribute/experiences/spans_subattribute.rb', line 23

def parse
  started = date_started(date_entry)
  finished = date_finished(dates_finished, date_index)
  return [] if started.nil? && finished.nil?

  progress_attr = ProgressSubattribute.new(date_entry:, variant_index:, columns:, config:)
  progress = progress_attr.parse

  [{
    dates: started..finished                || template.fetch(:dates),
    amount: length                          || template.fetch(:amount),
    progress: progress || (1.0 if finished) || template.fetch(:progress),
    name:                                   template.fetch(:name),
    favorite?:                              template.fetch(:favorite?),
  }]
end