Class: Reading::Item::View

Inherits:
Object show all
Defined in:
lib/reading/item/view.rb

Overview

A view object for an Item, providing shortcuts to information that is handy to show (for example) on a webpage.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ View

Returns a new instance of View.

Parameters:

  • item (Item)

    the Item from which to extract view information.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/reading/item/view.rb', line 12

def initialize(item)
  @genres = item.genres
  @rating = extract_star_or_rating(item)
  @isbn, @url, variant = extract_first_source_info(item)
  @name = extract_name(item, variant)
  @type_emoji = extract_type_emoji(variant&.format)
  @date_or_status = extract_date_or_status(item)
  @experience_count = item.experiences.count
  @groups = item.experiences.map(&:group).compact
  @blurb = item.notes.find(&:blurb?)&.content
  @public_notes = item.notes.reject(&:private?).reject(&:blurb?).map(&:content)
end

Instance Attribute Details

#blurbObject (readonly)

Returns the value of attribute blurb.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def blurb
  @blurb
end

#date_or_statusObject (readonly)

Returns the value of attribute date_or_status.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def date_or_status
  @date_or_status
end

#experience_countObject (readonly)

Returns the value of attribute experience_count.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def experience_count
  @experience_count
end

#genresObject (readonly)

Returns the value of attribute genres.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def genres
  @genres
end

#groupsObject (readonly)

Returns the value of attribute groups.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def groups
  @groups
end

#isbnObject (readonly)

Returns the value of attribute isbn.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def isbn
  @isbn
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def name
  @name
end

#public_notesObject (readonly)

Returns the value of attribute public_notes.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def public_notes
  @public_notes
end

#ratingObject (readonly)

Returns the value of attribute rating.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def rating
  @rating
end

#type_emojiObject (readonly)

Returns the value of attribute type_emoji.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def type_emoji
  @type_emoji
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/reading/item/view.rb', line 8

def url
  @url
end