Module: Reading::Parsing::Attributes::Shared
- Defined in:
- lib/reading/parsing/attributes/shared.rb
Overview
Sub-attributes that are shared across multiple attributes.
Class Method Summary collapse
-
.length(hash, format:, key_name: :length, episodic: false, ignore_repetitions: false) ⇒ Float, ...
Extracts the :length sub-attribute (pages or time) from the given hash.
-
.progress(hash, no_end_date: nil) ⇒ Float, ...
Extracts the :progress sub-attribute (percent, pages, or time) from the given hash.
Class Method Details
.length(hash, format:, key_name: :length, episodic: false, ignore_repetitions: false) ⇒ Float, ...
Extracts the :length sub-attribute (pages or time) from the given hash.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/reading/parsing/attributes/shared.rb', line 41 def self.length(hash, format:, key_name: :length, episodic: false, ignore_repetitions: false) return nil unless hash length = hash[:"#{key_name}_pages"]&.to_i || hash[:"#{key_name}_time"]&.then { Item::TimeLength.parse(_1) } return nil unless length if hash[:each] && !hash[:repetitions] # Length is calculated based on History column in this case. if episodic return length else return nil end end if hash[:repetitions] return length if episodic length *= hash[:repetitions].to_i unless ignore_repetitions else return nil if episodic && !hash[:each] end speed = Config.hash.deep_fetch(:speed, :format)[format] || 1.0 (length / speed).to_i_if_whole end |
.progress(hash, no_end_date: nil) ⇒ Float, ...
Extracts the :progress sub-attribute (percent, pages, or time) from the given hash.
15 16 17 18 19 20 21 22 23 |
# File 'lib/reading/parsing/attributes/shared.rb', line 15 def self.progress(hash, no_end_date: nil) hash[:progress_percent]&.to_f&./(100) || hash[:progress_pages]&.to_i || hash[:progress_time]&.then { Item::TimeLength.parse(_1) } || (0 if hash[:progress_dnf]) || (1.0 if hash[:progress_done]) || (0.0 if no_end_date) || nil end |