This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Record < ActiveRecord::Base | |
def self.process_records | |
all.each do |record| | |
begin | |
record.do_something | |
rescue | |
ErrorMailer.email(record).deliver | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :fragrantica do | |
require 'nokogiri' | |
require 'open-uri' | |
task :brands => :environment do | |
1.upto(11).each do |i| | |
brands_doc = Nokogiri::HTML(open("http://www.fragrantica.com/designers-#{i}/")) | |
brands_doc.css("div#col1 div.nduList a").each do |brand_anchor| | |
brand_name = brand_anchor.content[1..-2] | |
brand = Brand.where(name: brand_name).first_or_create do |brand| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_fragrance_notes(fragrance_doc) | |
fragrance_notes = [] | |
fragrance_doc.xpath('//div[@id="col1"]//div[@style="width: 230px; float: left; text-align: center; clear: left;"]/p').each do |notes_node| | |
if notes_node.content.include?('Top Notes') | |
note_type = FragranceNoteType.find_by_name('top') | |
elsif notes_node.content.include?('Middle Notes') | |
note_type = FragranceNoteType.find_by_name('middle') | |
elsif notes_node.content.include?('Base Notes') | |
note_type = FragranceNoteType.find_by_name('base') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fragrance < ActiveRecord::Base | |
belongs_to :brand | |
validates_presence_of :brand, :name | |
validates_uniqueness_of :name, scope: :brand | |
has_many :pictures, -> { order(:order) }, class_name: 'FragrancePicture', dependent: :destroy | |
accepts_nested_attributes_for :pictures, allow_destroy: true | |
has_many :inventory_items, dependent: :destroy | |
has_many :opinions, class_name: 'FragranceOpinion', dependent: :destroy | |
has_many :reviews, class_name: 'FragranceReview', dependent: :destroy | |
has_many :notes, class_name: 'FragranceNote', dependent: :destroy |