Sha256: 525248a98de031095597d396cb6f52c8c604df8a2af90347e7a1fc49b99f6e50

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 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

21 entries across 21 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 lib/bhf/settings/base.rb
bhf-1.0.0.beta15 lib/bhf/settings/base.rb
bhf-1.0.0.beta14 lib/bhf/settings/base.rb
bhf-1.0.0.beta13 lib/bhf/settings/base.rb
bhf-1.0.0.beta12 lib/bhf/settings/base.rb
bhf-1.0.0.beta11 lib/bhf/settings/base.rb
bhf-1.0.0.beta10 lib/bhf/settings/base.rb
bhf-1.0.0.beta9 lib/bhf/settings/base.rb
bhf-1.0.0.beta8 lib/bhf/settings/base.rb
bhf-1.0.0.beta7 lib/bhf/settings/base.rb
bhf-1.0.0.beta6 lib/bhf/settings/base.rb
bhf-1.0.0.beta5 lib/bhf/settings/base.rb
bhf-1.0.0.beta4 lib/bhf/settings/base.rb
bhf-1.0.0.beta3 lib/bhf/settings/base.rb
bhf-1.0.0.beta2 lib/bhf/settings/base.rb
bhf-1.0.0.beta1 lib/bhf/settings/base.rb
bhf-0.10.17 lib/bhf/settings/base.rb
bhf-0.10.16 lib/bhf/settings/base.rb
bhf-0.10.15 lib/bhf/settings/base.rb
bhf-0.10.14 lib/bhf/settings/base.rb