Sha256: 10c8b6794bf5787f0d68085b393805f6c38ac6bdd89caa864f77ca8f98acec6a

Contents?: true

Size: 1.34 KB

Versions: 20

Compression:

Stored size: 1.34 KB

Contents

module Bhf::Settings

  class Base
    
    attr_accessor :user

    def initialize(settings_hash, user = nil)
      @settings_hash = settings_hash
      @user = user
      
      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

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

    def content_for_page(selected_page)
      @settings_hash['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

    def find_platform_settings(platform_name)
      pages.each do |page|
        content_for_page(page).each do |platform_hash|
          if platform_hash.keys[0] == platform_name.to_s
            return Bhf::Settings::Platform.new(platform_hash, page, self)
          end
        end
      end
      nil
    end

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
bhf-0.10.12 lib/bhf/settings/base.rb
bhf-0.10.11 lib/bhf/settings/base.rb
bhf-0.10.10 lib/bhf/settings/base.rb
bhf-0.10.9 lib/bhf/settings/base.rb
bhf-0.9.9 lib/bhf/settings/base.rb
bhf-0.9.8 lib/bhf/settings/base.rb
bhf-0.9.7 lib/bhf/settings/base.rb
bhf-0.9.6 lib/bhf/settings/base.rb
bhf-0.9.5 lib/bhf/settings/base.rb
bhf-0.9.4 lib/bhf/settings/base.rb
bhf-0.9.3 lib/bhf/settings/base.rb
bhf-0.9.2 lib/bhf/settings/base.rb
bhf-0.9.1 lib/bhf/settings/base.rb
bhf-0.9.0 lib/bhf/settings/base.rb
bhf-0.8.7 lib/bhf/settings/base.rb
bhf-0.8.6 lib/bhf/settings/base.rb
bhf-0.8.5 lib/bhf/settings/base.rb
bhf-0.8.4 lib/bhf/settings/base.rb
bhf-0.8.3 lib/bhf/settings/base.rb
bhf-0.8.2 lib/bhf/settings/base.rb