Class: Ecic::Library
- Inherits:
-
Object
- Object
- Ecic::Library
- Defined in:
- lib/ecic/library.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#project ⇒ Object
Returns the value of attribute project.
-
#source_files ⇒ Object
Returns the value of attribute source_files.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #already_exists? ⇒ Boolean
- #create ⇒ Object
-
#initialize(project, name, type, options = {}) ⇒ Library
constructor
A new instance of Library.
- #is_a_testbench? ⇒ Boolean
- #is_valid? ⇒ Boolean
- #load_sources ⇒ Object
-
#source_file(path) ⇒ Object
Function used in sources.rb file of each library.
- #to_json(options = {}) ⇒ Object
- #to_s(options = {}) ⇒ Object
- #to_str(options = {}) ⇒ Object
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, ={}) opt = {:path => nil}.merge() @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
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/ecic/library.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/ecic/library.rb', line 5 def path @path end |
#project ⇒ Object
Returns the value of attribute project.
5 6 7 |
# File 'lib/ecic/library.rb', line 5 def project @project end |
#source_files ⇒ Object
Returns the value of attribute source_files.
6 7 8 |
# File 'lib/ecic/library.rb', line 6 def source_files @source_files end |
#type ⇒ Object (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
38 39 40 |
# File 'lib/ecic/library.rb', line 38 def already_exists? @project.has_library?(self) end |
#create ⇒ Object
33 34 35 36 |
# File 'lib/ecic/library.rb', line 33 def create validate_name @project.add_library self end |
#is_a_testbench? ⇒ Boolean
79 80 81 |
# File 'lib/ecic/library.rb', line 79 def is_a_testbench? @type == :testbench end |
#is_valid? ⇒ 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_sources ⇒ Object
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.}" 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( = {}) incl_src_files = [: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(={}) str = name incl_src_files = [: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(={}) to_s() end |