Class: Ecic::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/ecic/library.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, name, type, options = {}) ⇒ Library

Returns a new instance of Library.



10
11
12
13
14
15
16
17
18
19
# File 'lib/ecic/library.rb', line 10

def initialize(project, name, type, options={})
  opt = {:path => nil}.merge(options)
  @project = project
  @type = type
  @name = name
  default_path = {:testbench => "src/testbench/#{@name}",
                  :design    => "src/design/#{@name}"}
  @path = opt[:path] || default_path[@type]
  @source_files = []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ecic/library.rb', line 5

def name
  @name
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/ecic/library.rb', line 5

def path
  @path
end

#projectObject

Returns the value of attribute project.



5
6
7
# File 'lib/ecic/library.rb', line 5

def project
  @project
end

#source_filesObject

Returns the value of attribute source_files.



6
7
8
# File 'lib/ecic/library.rb', line 6

def source_files
  @source_files
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/ecic/library.rb', line 7

def type
  @type
end

Instance Method Details

#already_exists?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ecic/library.rb', line 38

def already_exists?
  @project.has_library?(self)
end

#createObject



33
34
35
36
# File 'lib/ecic/library.rb', line 33

def create
  validate_name
  @project.add_library self      
end

#is_a_testbench?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/ecic/library.rb', line 79

def is_a_testbench?
  @type == :testbench
end

#is_valid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ecic/library.rb', line 21

def is_valid?
  begin
    validate_name
    return false if already_exists?
    #TBA: validate unique name as well
    return true
    #TBA: 'validate_name' should raise a specific naming exception and only this specific exception should be caught. 
  rescue Exception => exc
    return false
  end
end

#load_sourcesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ecic/library.rb', line 63

def load_sources
  src_file = File.join(@project.root, @path, 'sources.rb')
  if File.exists?(src_file)
    begin
      puts "reading #{src_file} ..."
      eval File.read(src_file)
    rescue Exception => exc
      raise "Syntax error occurred while reading #{src_file}: #{exc.message}"
    end
  else
#        p @path
#        p @type
    raise "Could not read sources for #{name} library. #{src_file} file does not exist"
  end
end

#source_file(path) ⇒ Object

Function used in sources.rb file of each library



84
85
86
87
88
89
# File 'lib/ecic/library.rb', line 84

def source_file(path)
#      puts "Creating new source file"
  new_src = SourceFile.new(self, path)
  source_files << new_src
  new_src
end

#to_json(options = {}) ⇒ Object



56
57
58
59
60
61
# File 'lib/ecic/library.rb', line 56

def to_json(options = {})
  incl_src_files = options[:include_source_files] || false
  hash = {:name => name, :path => path}
  hash[:source_files] = source_files if incl_src_files
  hash.to_json
end

#to_s(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ecic/library.rb', line 46

def to_s(options={})
  str = name
  incl_src_files = options[:include_source_files] || false
  if incl_src_files
    str += ":"
    str += "\n  " + source_files.join("\n  ") unless source_files.length == 0
  end
  str
end

#to_str(options = {}) ⇒ Object



42
43
44
# File 'lib/ecic/library.rb', line 42

def to_str(options={})
  to_s(options)
end