module Origen::Features::ClassMethods

Public Instance Methods

features() click to toggle source
# File lib/origen/features.rb, line 8
def features
  @features ||= {}
end

Private Instance Methods

define_file(file) click to toggle source
# File lib/origen/features.rb, line 45
def define_file(file)
  if Origen.running_on_windows?
    fields = file.split(':')
    "#{fields[0]}:#{fields[1]}"
  else
    file.split(':').first

  end
end
description_lookup() click to toggle source
# File lib/origen/features.rb, line 55
def description_lookup
  @@description_lookup ||= {}
end
feature(name, options = {}) click to toggle source

Creates a Feature if it deos not already exists. Returns the Feature object if it already exists. Returns an array of features if no argument is provided.

# File lib/origen/features.rb, line 18
def feature(name, options = {})
  name = name.to_s.downcase.to_sym
  if !features.key?(name)
    # Add the feature if it does not already exists

    # Read desciption from the caller if the description of feature
    # is not provided
    unless options.key?(:description)
      @file = define_file(caller[0])
      options[:description] = fetch_description(name)
    end
    features[name] = Feature.new(name, options)
  else # if feature with given name already exists
    fail "Feature #{name} already added!"
  end
end
fetch_description(name) click to toggle source
# File lib/origen/features.rb, line 35
def fetch_description(name)
  parse_description unless description_lookup[@file]
  begin
    desc = description_lookup[@file][name]
  rescue
    desc = []
  end
  desc
end
parse_description() click to toggle source
# File lib/origen/features.rb, line 59
def parse_description
  desc = []
  File.readlines(@file).each do |line|
    if line =~ /^\s*#(.*)/
      desc << Regexp.last_match[1].strip
    elsif line =~ /(\s|:)feature(\s*)(=?>?)(\s?):(\w*)/
      description_lookup[@file] ||= {}
      description_lookup[@file][Regexp.last_match[5].to_sym] = desc
      desc = []
    else
      desc = []
    end
  end
end