Class: Reading::Row

Inherits:
Object show all
Defined in:
lib/reading/row/row.rb,
lib/reading/attribute/attribute.rb,
lib/reading/attribute/all_attributes.rb,
lib/reading/attribute/variants/variants_attribute.rb,
lib/reading/attribute/variants/length_subattribute.rb,
lib/reading/attribute/variants/series_subattribute.rb,
lib/reading/attribute/variants/sources_subattribute.rb,
lib/reading/attribute/experiences/spans_subattribute.rb,
lib/reading/attribute/variants/extra_info_subattribute.rb,
lib/reading/attribute/experiences/experiences_attribute.rb,
lib/reading/attribute/experiences/progress_subattribute.rb

Overview

A base class that contains behaviors common to ___Row classes.

Direct Known Subclasses

BlankRow, CompactPlannedRow, RegularRow

Defined Under Namespace

Classes: Attribute, AuthorAttribute, ExperiencesAttribute, ExtraInfoSubattribute, GenresAttribute, LengthSubattribute, NotesAttribute, ProgressSubattribute, RatingAttribute, SeriesSubattribute, SourcesSubattribute, SpansSubattribute, TitleAttribute, VariantsAttribute

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Row

Returns a new instance of Row.

Parameters:



11
12
13
14
15
# File 'lib/reading/row/row.rb', line 11

def initialize(line)
  @line = line

  after_initialize
end

Instance Method Details

#parseArray<Hash>

Parses a CSV row into an array of hashes of item data. How this is done depends on how the template methods (further below) are implemented in subclasses of Row.

Returns:

  • (Array<Hash>)

    an array of hashes like the template in config.rb



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/reading/row/row.rb', line 21

def parse
  return [] if skip?

  before_parse

  items = item_heads.map { |item_head|
    item_hash(item_head)
      .compact_by(template: config.deep_fetch(:item, :template))
  }.compact

  items

rescue Reading::Error => e
  e.handle(line:)
  []
end