Sha256: c3a51626e42e63cf6ed83819c5f4a9c8bdbc3fff3eaedfb0f90fa8c11b41fe06

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'ascii_binder_gabriel_rh/helpers'

include AsciiBinderGabrielRH::Helpers

module AsciiBinderGabrielRH
  class Site
    attr_reader :id, :name, :url

    def initialize(distro_config)
      @id   = distro_config['site']
      @name = distro_config['site_name']
      @url  = distro_config['site_url']
    end

    def is_valid?
      validate
    end

    def errors
      validate(true)
    end

    private

    def validate(verbose=false)
      errors = []
      unless valid_id?(@id)
        if verbose
          errors << "Site ID '#{@id}' is not a valid ID."
        else
          return false
        end
      end
      unless valid_string?(@name)
        if verbose
          errors << "Site name '#{@name}' for site ID '#{@id}' is not a valid string."
        else
          return false
        end
      end
      unless valid_string?(@url)
        if verbose
          errors << "Site URL '#{@url}' for site ID '#{@id}' is not a valid string."
        else
          return false
        end
      end
      return errors if verbose
      return true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ascii_binder_gabriel_rh-0.0.1 lib/ascii_binder_gabriel_rh/site.rb