class BomDB::Models::Edition

Public Class Methods

new(db) click to toggle source
# File lib/bomdb/models/edition.rb, line 4
def initialize(db)
  @db = db
end

Public Instance Methods

find(edition_name_prefix) click to toggle source

Find an edition and return a hash, or nil if not found

# File lib/bomdb/models/edition.rb, line 9
def find(edition_name_prefix)
  @db[:editions].
    where(Sequel.like(:edition_name, "#{edition_name_prefix}%")).
    or(:edition_year => edition_name_prefix).
    first
end
find_or_create(year, name) click to toggle source

Returns an edition_id, either found in the db, or created as necessary

# File lib/bomdb/models/edition.rb, line 17
def find_or_create(year, name)
  found = @db[:editions].where(edition_year: year, edition_name: name).first
  return found[:edition_id] if found
  @db[:editions].insert(
    edition_year: year,
    edition_name: name
  )
end