Class: Reading::Parsing::Attributes::Rating

Inherits:
Attribute show all
Defined in:
lib/reading/parsing/attributes/rating.rb

Overview

Transformer for the :rating item attribute.

Instance Method Summary collapse

Instance Method Details

#transform_from_parsed(parsed_row, _head_index) ⇒ Integer, Float

Parameters:

  • parsed_row (Hash)

    a parsed row (the intermediate hash).

  • _head_index (Integer)

    current item’s position in the Head column.

Returns:

  • (Integer, Float)


9
10
11
12
13
# File 'lib/reading/parsing/attributes/rating.rb', line 9

def transform_from_parsed(parsed_row, _head_index)
  rating = parsed_row[:rating]&.dig(:number)

  Integer(rating, exception: false) || Float(rating, exception: false)
end