class RubyPocket::FavoriteCreator

Attributes

web_page[W]

Public Class Methods

new(params) click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 14
def initialize(params)
  @params = params
end

Public Instance Methods

favorite=(favorite) click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 18
def favorite=(favorite)
  fail 'Must be a new favorite' unless favorite.new?
  @favorite = favorite
end
save() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 23
def save
  fetch_missing_data
  assign_params
  save_favorite
end

Private Instance Methods

assign_params() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 44
def assign_params
  favorite.set_all @params
end
favorite() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 54
def favorite
  @favorite ||= Favorite.new
end
fetch_missing_data() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 31
def fetch_missing_data
  return if @params[:name]
  return unless web_page_contents

  @params[:name] = web_page_contents.title
end
save_favorite() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 48
def save_favorite
  favorite.save
rescue Sequel::ValidationFailed => e
  raise ValidationError, e.message
end
web_page() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 58
def web_page
  @web_page ||= WebPage
end
web_page_contents() click to toggle source
# File lib/ruby_pocket/favorite_creator.rb, line 38
def web_page_contents
  return unless @params[:url]

  @page ||= web_page.for(@params[:url])
end