verilog 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/verilog.rb +2 -1
- data/lib/verilog/file.rb +13 -7
- data/lib/verilog/path.rb +56 -0
- data/spec/{verilog_spec.rb → verilog_file_spec.rb} +8 -0
- data/spec/verilog_path_spec.rb +42 -0
- metadata +7 -5
data/lib/verilog.rb
CHANGED
data/lib/verilog/file.rb
CHANGED
@@ -6,9 +6,19 @@ module Verilog
|
|
6
6
|
attr_accessor :filename, :contents
|
7
7
|
|
8
8
|
def initialize( filename, options={} )
|
9
|
-
@filename = filename
|
9
|
+
@filename = ::File.basename( filename )
|
10
10
|
@options = options
|
11
|
-
|
11
|
+
|
12
|
+
options[:path] ||= ''
|
13
|
+
relative_path_added_with_file_name = filename.dup
|
14
|
+
#Remove the basename section of the filename
|
15
|
+
relative_path_added_with_file_name[@filename] = ''
|
16
|
+
|
17
|
+
@options[:path] = ::File.join( options[:path], relative_path_added_with_file_name )
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
[":options => #{@options.inspect}", ":filename => #{@filename}", ":contents => #{@contents}"]
|
12
22
|
end
|
13
23
|
|
14
24
|
#Alias method
|
@@ -35,11 +45,7 @@ module Verilog
|
|
35
45
|
end
|
36
46
|
|
37
47
|
def absolute_filename
|
38
|
-
|
39
|
-
dir = @filename.dup
|
40
|
-
else
|
41
|
-
dir = ::File.join( @options[:path], @filename )
|
42
|
-
end
|
48
|
+
dir = ::File.join( @options[:path], @filename )
|
43
49
|
dir = ::File.expand_path( dir )
|
44
50
|
|
45
51
|
return dir
|
data/lib/verilog/path.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
module Verilog
|
3
|
+
|
4
|
+
class Path
|
5
|
+
attr_reader :files
|
6
|
+
|
7
|
+
def initialize( path="" )
|
8
|
+
@files = []
|
9
|
+
load_path( path )
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_path( paths )
|
13
|
+
#path is single string or array of strings
|
14
|
+
paths.each do |path|
|
15
|
+
files = Dir.glob( ::File.join( path, '*.*') )
|
16
|
+
files.each do |file|
|
17
|
+
#Skip if Directory got passed *.* Filter
|
18
|
+
next if ::File.directory?( file )
|
19
|
+
|
20
|
+
file_name = ::File.basename(file)
|
21
|
+
@files << Verilog::File.new(file_name, {:path => path})
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_file file
|
28
|
+
@files << Verilog::File.new( file )
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_all
|
32
|
+
@files.each do |file|
|
33
|
+
file.read_from_disk
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_by_module( name )
|
38
|
+
result = @files.select do |file|
|
39
|
+
file.module_name == name
|
40
|
+
end
|
41
|
+
|
42
|
+
return result[0]
|
43
|
+
end
|
44
|
+
|
45
|
+
def includes_file( name )
|
46
|
+
@files.select { |file| file.includes.include?( name ) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def instantiates_module( name )
|
50
|
+
@files.select { |file| file.instantiations.include?( name ) }
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
@@ -2,6 +2,14 @@ require 'spec_helper'
|
|
2
2
|
require 'pp'
|
3
3
|
|
4
4
|
describe Verilog do
|
5
|
+
it "Checking initialize equivalence, file and path verus absolute path" do
|
6
|
+
path = File.dirname( __FILE__ )
|
7
|
+
|
8
|
+
test_one = Verilog::File.new( File.join( path, 'fixtures', 'test_one.v' ) )
|
9
|
+
test_one.inspect.should == Verilog::File.new( 'test_one.v',{:path => File.join( path, 'fixtures')} ).inspect
|
10
|
+
end
|
11
|
+
|
12
|
+
|
5
13
|
|
6
14
|
it "Open file, with path as oart of filename" do
|
7
15
|
path = File.dirname( __FILE__ )
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
describe Verilog do
|
5
|
+
|
6
|
+
it "initialize with folder" do
|
7
|
+
path = File.dirname( __FILE__ )
|
8
|
+
|
9
|
+
test_one = Verilog::Path.new( File.join( path, 'fixtures' ) )
|
10
|
+
test_one.read_all
|
11
|
+
|
12
|
+
answer = Verilog::File.new( File.join( path, 'fixtures', 'test_one.v' ) )
|
13
|
+
answer.read
|
14
|
+
test_one.find_by_module( "TEST_ONE" ).inspect.should == answer.inspect
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it "initialize with no args" do
|
19
|
+
path = File.dirname( __FILE__ )
|
20
|
+
|
21
|
+
test_one = Verilog::Path.new( )
|
22
|
+
test_one.read_all
|
23
|
+
|
24
|
+
answer = nil# Verilog::File.new( File.join( path, 'fixtures', 'test_one.v' ) )
|
25
|
+
test_one.find_by_module( "TEST_ONE" ).inspect.should == answer.inspect
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it "initialize with no args, and load_file" do
|
30
|
+
path = File.dirname( __FILE__ )
|
31
|
+
|
32
|
+
test_one = Verilog::Path.new( )
|
33
|
+
test_one.load_file( File.join( path, 'fixtures', 'test_one.v' ) )
|
34
|
+
test_one.read_all
|
35
|
+
|
36
|
+
answer = Verilog::File.new( File.join( path, 'fixtures', 'test_one.v' ) )
|
37
|
+
answer.read
|
38
|
+
test_one.find_by_module( "TEST_ONE" ).inspect.should == answer.inspect
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verilog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morgan Prior
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-25 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -32,12 +32,14 @@ files:
|
|
32
32
|
- README.md
|
33
33
|
- Rakefile
|
34
34
|
- lib/verilog/file.rb
|
35
|
+
- lib/verilog/path.rb
|
35
36
|
- lib/verilog.rb
|
36
37
|
- spec/fixtures/test_four.vh
|
37
38
|
- spec/fixtures/test_one.v
|
38
39
|
- spec/fixtures/test_three.v
|
39
40
|
- spec/spec_helper.rb
|
40
|
-
- spec/
|
41
|
+
- spec/verilog_file_spec.rb
|
42
|
+
- spec/verilog_path_spec.rb
|
41
43
|
has_rdoc: true
|
42
44
|
homepage: http://amaras-tech.co.uk/software/verilog
|
43
45
|
licenses: []
|