Class: Verilog::File
- Inherits:
-
Object
- Object
- Verilog::File
- Defined in:
- lib/verilog/file.rb
Overview
< Class::File
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #absolute_filename ⇒ Object
- #includes ⇒ Object
-
#initialize(filename, options = {}) ⇒ File
constructor
A new instance of File.
- #inspect ⇒ Object
- #instantiations ⇒ Object
- #module_name ⇒ Object
- #read ⇒ Object
-
#read_from_disk ⇒ Object
Alias method.
- #save ⇒ Object
Constructor Details
#initialize(filename, options = {}) ⇒ File
Returns a new instance of File.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/verilog/file.rb', line 8 def initialize( filename, ={} ) @filename = ::File.basename( filename ) @options = [:path] ||= '' relative_path_added_with_file_name = filename.dup #Remove the basename section of the filename relative_path_added_with_file_name[@filename] = '' @options[:path] = ::File.join( [:path], relative_path_added_with_file_name ) end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
6 7 8 |
# File 'lib/verilog/file.rb', line 6 def contents @contents end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/verilog/file.rb', line 6 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/verilog/file.rb', line 5 def @options end |
Instance Method Details
#absolute_filename ⇒ Object
47 48 49 50 51 52 |
# File 'lib/verilog/file.rb', line 47 def absolute_filename dir = ::File.join( @options[:path], @filename ) dir = ::File.( dir ) return dir end |
#includes ⇒ Object
71 72 73 74 75 76 |
# File 'lib/verilog/file.rb', line 71 def includes inc = [] @contents.scan(/(^\s*`include [\'\"])(.*)([\'\"])/i){ inc << $2 } return inc end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/verilog/file.rb', line 20 def inspect [":options => #{@options.inspect}", ":filename => #{@filename}", ":contents => #{@contents}"] end |
#instantiations ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/verilog/file.rb', line 62 def instantiations inst = [] @contents.scan(/(^\s*)(\w*)\s+\w+\s*(\([.,\(\)\w\s]*\))?;/mi){ inst << $2 } #Hack, module will also match the instatiation syntax, rempve via array subtraction inst = inst - ['module'] return inst end |
#module_name ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/verilog/file.rb', line 54 def module_name if @contents.match(/(^\s*module *)(.*)(;|\s*\()/i) return $2 else return "" end end |
#read ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/verilog/file.rb', line 29 def read if ::File.exist?( absolute_filename ) ::File.open( absolute_filename, "rb") do |f| @contents = f.read end else #TODO raise correct exception here $stderr.puts "ERROR File Not Found #{absolute_filename}" end end |
#read_from_disk ⇒ Object
Alias method
25 26 27 |
# File 'lib/verilog/file.rb', line 25 def read_from_disk read() end |
#save ⇒ Object
41 42 43 44 45 |
# File 'lib/verilog/file.rb', line 41 def save ::File.open( absolute_filename, "w" ) do |f| f.write @contents end end |