module BeerList

Public Class Methods

add_establishment(*args) click to toggle source
# File lib/beer_list.rb, line 53
def add_establishment(*args)
  args.each do |e|
    _establishments << e if e.respond_to?(:get_list)
  end
end
Also aliased as: add_establishments
add_establishments(*args)
Alias for: add_establishment
clear_establishments!() click to toggle source
# File lib/beer_list.rb, line 49
def clear_establishments!
  @establishments.clear if @establishments
end
configure() { |settings| ... } click to toggle source
# File lib/beer_list.rb, line 18
def configure
  yield settings
  true
end
default_url() click to toggle source
# File lib/beer_list.rb, line 27
def default_url
  settings.default_url
end
establishments() click to toggle source
# File lib/beer_list.rb, line 44
def establishments
  return [] if @establishments.nil?
  @establishments.dup
end
establishments_dir() click to toggle source
# File lib/beer_list.rb, line 31
def establishments_dir
  settings.establishments_dir
end
establishments_dir=(directory) click to toggle source

DEPRECATED ###

# File lib/beer_list.rb, line 36
    def establishments_dir=(directory)
      puts <<-dep
        BeerList.establishments_dir= is deprecated and will be removed.
        Please use BeerList.configure instead
      dep
      settings.establishments_dir = directory
    end
lists() click to toggle source
# File lib/beer_list.rb, line 60
def lists
  raise NoEstablishmentsError if establishments.empty?

  return @lists unless update_necessary?
  @lists = establishments.map do |e|
    scraper.beer_list e
  end
end
lists_as_hash() click to toggle source
# File lib/beer_list.rb, line 69
def lists_as_hash
  lists.inject({}) do |hsh, list|
    hsh.merge! list.to_hash
  end
end
lists_as_json() click to toggle source
# File lib/beer_list.rb, line 75
def lists_as_json
  lists_as_hash.to_json
end
scraper() click to toggle source
# File lib/beer_list.rb, line 92
def scraper
  @scraper ||= Scraper.instance
end
send_list(list, url=nil) click to toggle source
# File lib/beer_list.rb, line 79
def send_list(list, url=nil)
  url ||= default_url
  raise NoUrlError unless url
  raise NotAListError unless list.is_a? BeerList::List
  scraper.send_json url, list.to_json
end
send_lists(url=nil) click to toggle source
# File lib/beer_list.rb, line 86
def send_lists(url=nil)
  url ||= default_url
  raise NoUrlError unless url
  scraper.send_json url, lists_as_json
end
settings() click to toggle source
# File lib/beer_list.rb, line 23
def settings
  @settings ||= Settings.new
end

Private Class Methods

_establishments() click to toggle source
# File lib/beer_list.rb, line 102
def _establishments
  @establishments ||= []
end
establishments_eq_lists?() click to toggle source
# File lib/beer_list.rb, line 106
def establishments_eq_lists?
  list_names = @lists.map(&:establishment)
  establishments.map(&:short_class_name).all? { |name| list_names.include? name }
end
get_class_with_namespace(class_name) click to toggle source
# File lib/beer_list.rb, line 124
def get_class_with_namespace(class_name)
  return nil unless is_establishment? class_name
  ['BeerList', 'Establishments', class_name].inject(Object){ |o, name| o.const_get(name) }
end
is_establishment?(class_name) click to toggle source
# File lib/beer_list.rb, line 120
def is_establishment?(class_name)
  BeerList::Establishments.constants.include? class_name.to_sym
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/beer_list.rb, line 111
def method_missing(method, *args, &block)
  class_name = method.to_s.split('_').map(&:capitalize).join
  if klass = get_class_with_namespace(class_name)
    scraper.beer_list klass.new
  else
    super
  end
end
update_necessary?() click to toggle source
# File lib/beer_list.rb, line 98
def update_necessary?
  !@lists || !establishments_eq_lists?
end