app/models/taxon.rb
# Sometimes you don't want to make a new taxon name with a taxon, like when
# you're saving a new taxon name with a new associated taxon. Hence, this.
Sometimes you don't want to make a new taxon name with a taxon, like when
you're saving a new taxon name with a new associated taxon. Hence, this.
Sometimes you don ' t want to make a new taxon name with a taxon like when you ' re saving a new taxon name with a new associated taxon . Hence this .
def wikipedia_summary(options = {})
    locale = options[:locale] || I18n.locale
    td = taxon_descriptions.detect{|td| td.locale.to_s == locale.to_s}
    td ||= taxon_descriptions.detect{|td| td.locale.to_s =~ /^#{locale.to_s.split('-').first}/}
    sum = if td
      td.body.to_s[0..500]
    elsif locale.to_s =~ /^en-?/
      read_attribute(:wikipedia_summary)
    end
    if sum && sum.match(/^\d\d\d\d-\d\d-\d\d$/)
      last_try_date = DateTime.parse(sum)
      return nil if last_try_date > 1.week.ago
      options[:reload] = true
    end
    unless sum.blank? || options[:reload]
      return Nokogiri::HTML::DocumentFragment.parse(sum).to_s
    end
    if !new_record? && options[:refresh_if_blank] && !Delayed::Job.where("handler LIKE '%set_wikipedia_summary%id: ''#{id}''%'").exists?
      delay(:priority => OPTIONAL_PRIORITY).set_wikipedia_summary(:locale => locale)
    end
    nil
  end
def wikipedia_summary ( options = { } ) locale = options [ :locale ] || I18n . locale td = taxon_descriptions . detect { | td | td . locale . to_s == locale . to_s } td ||= taxon_descriptions . detect { | td | td . locale . to_s =~ / ^ #{ locale . to_s . split ( '-' ) . first } / } sum = if td td . body . to_s [ 0 .. 500 ] elsif locale . to_s =~ / ^en-? / read_attribute ( :wikipedia_summary ) end if sum && sum . match ( / ^ \d \d \d \d - \d \d - \d \d $ / ) last_try_date = DateTime . parse ( sum ) return nil if last_try_date > 1 . week . ago options [ :reload ] = true end unless sum . blank? || options [ :reload ] return Nokogiri :: HTML :: DocumentFragment . parse ( sum ) . to_s end if ! new_record? && options [ :refresh_if_blank ] && ! Delayed :: Job . where ( "handler LIKE '%set_wikipedia_summary%id: ''#{id}''%'" ) . exists? delay ( :priority => OPTIONAL_PRIORITY ) . set_wikipedia_summary ( :locale => locale ) end nil end
Sometimes you don't want to make a new taxon name with a taxon, like when
you're saving a new taxon name with a new associated taxon.
Sometimes you don ' t want to make a new taxon name with a taxon like when you ' re saving a new taxon name with a new associated taxon .
options