Sha256: 5b49db01d223141a383b95c101b0c106d93584e413ae79c8eadaf9f7010e4078

Contents?: true

Size: 1.04 KB

Versions: 16

Compression:

Stored size: 1.04 KB

Contents

require 'ascii_binder/helpers'

include AsciiBinder::Helpers

module AsciiBinder
  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

16 entries across 16 versions & 1 rubygems

Version Path
ascii_binder-1.2 lib/ascii_binder/site.rb
ascii_binder-1.0.1 lib/ascii_binder/site.rb
ascii_binder-1.0 lib/ascii_binder/site.rb
ascii_binder-0.2.3 lib/ascii_binder/site.rb
ascii_binder-0.2.2 lib/ascii_binder/site.rb
ascii_binder-0.2.1 lib/ascii_binder/site.rb
ascii_binder-0.2.0 lib/ascii_binder/site.rb
ascii_binder-0.1.15.3 lib/ascii_binder/site.rb
ascii_binder-0.1.15.2 lib/ascii_binder/site.rb
ascii_binder-0.1.15.1 lib/ascii_binder/site.rb
ascii_binder-0.1.15 lib/ascii_binder/site.rb
ascii_binder-0.1.14 lib/ascii_binder/site.rb
ascii_binder-0.1.13 lib/ascii_binder/site.rb
ascii_binder-0.1.11 lib/ascii_binder/site.rb
ascii_binder-0.1.10.1 lib/ascii_binder/site.rb
ascii_binder-0.1.10 lib/ascii_binder/site.rb