Class: Bhf::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/bhf/settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Settings

Returns a new instance of Settings.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bhf/settings.rb', line 5

def initialize(options)
  @options = options
  
  t = pages.each_with_object([]) do |page, obj|
    content_for_page(page).each do |platform|
      obj << platform.keys.flatten
    end
  end.flatten!
  if t.nil?
    raise Exception.new("No Bhf Pages found")
  end
  if t.uniq.length != t.length
    raise Exception.new("Platforms with identical names: '#{t.detect{ |e| t.count(e) > 1 }}'")
  end
end

Instance Method Details

#content_for_page(selected_page) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/bhf/settings.rb', line 31

def content_for_page(selected_page)
  @options['pages'].each do |page|
    page = {page => nil} if page.is_a?(String)
    
    if selected_page == page.keys[0]
      return page.values.flatten
    end
  end
  nil
end

#find_platform(platform_name, current_account = nil) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/bhf/settings.rb', line 42

def find_platform(platform_name,  = nil)
  pages.each do |page|
    content_for_page(page).each do |platform|
      bhf_platform = Bhf::Platform.new(platform, page, )
      return bhf_platform if bhf_platform.name == platform_name
    end
  end
end

#pagesObject



21
22
23
24
25
26
27
28
29
# File 'lib/bhf/settings.rb', line 21

def pages
  return @pages if @pages
  @pages = @options['pages'].each_with_object([]) do |page, obj|
    if page.is_a?(String)
      page = {page => nil}
    end
    obj << page.keys[0]
  end
end