require 'yaml'

module Scriptura
  module Scripture
    def self.old_testament_books
      books = []
      (1..39).each do |book_number|
        books << ScriptureBook.new(book_number)
      end
      books
    end

    def self.new_testament_books
      books = []
      (40..66).each do |book_number|
        books << ScriptureBook.new(book_number)
      end
      books
    end

    def self.books
      old_testament_books + new_testament_books
    end

    def self.book_names
      books.map(&:name)
    end

    def self.metadata
      @metadata ||= begin
        YAML.load_file('lib/scriptura/metadata.yml')
      end
    end

    def self.find_book_hash attribute, value
      metadata.values.find { |book| book[attribute.to_s] == value }
    end
  end
end

require 'yaml'

module Scriptura
  module Scripture
    HOME_PATH = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
    METADATA_FILE = File.join(HOME_PATH, 'lib', 'scriptura', 'metadata.yml')

    def self.old_testament_books
      books = []
      (1..39).each do |book_number|
        books << ScriptureBook.new(book_number)
      end
      books
    end

    def self.new_testament_books
      books = []
      (40..66).each do |book_number|
        books << ScriptureBook.new(book_number)
      end
      books
    end

    def self.books
      old_testament_books + new_testament_books
    end

    def self.book_names
      books.map(&:name)
    end

    def self.metadata
      @metadata ||= YAML.load_file(METADATA_FILE)
    end

    def self.find_book_hash attribute, value
      metadata.values.find { |book| book[attribute.to_s] == value }
    end
  end
end

Use better way to load yml file
Use better way to load yml file

For some reason the yaml file is not found when using the gem with an
application. Apparently that problem was not hit when using json.

Using a better more absolute approach of loading the yaml file. I took
this pattern from rubocop gem.
