Class: Banalize::Parser
- Inherits:
-
Object
- Object
- Banalize::Parser
- Includes:
- PodStyleComments, ShellVariables
- Defined in:
- lib/banalize/parser.rb,
lib/banalize/parser/variables.rb,
lib/banalize/parser/pod_comments.rb
Overview
Direct Known Subclasses
Defined Under Namespace
Modules: PodStyleComments, ShellVariables
Instance Attribute Summary collapse
-
#code ⇒ Object
Contains all non-comments of the script, excluding shebang line.
-
#comments ⇒ Object
Contains all block comments of the file, excluding shebang line.
-
#lines ⇒ Object
Lines of the tested bash file, split by n‘s.
-
#path ⇒ Object
UNIX path to the tested file.
-
#shebang ⇒ Object
Shebang contains first line of the script if it’s in ‘#!` format.
Attributes included from ShellVariables
Instance Method Summary collapse
-
#initialize(path) ⇒ Parser
constructor
A new instance of Parser.
Methods included from ShellVariables
Methods included from PodStyleComments
Constructor Details
#initialize(path) ⇒ Parser
Returns a new instance of Parser.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/banalize/parser.rb', line 21 def initialize path @lines = IO.read(path).force_encoding("utf-8").split($/) @shebang = Numbered.new @comments = Numbered.new @code = Numbered.new @variables = [] @shebang.add @lines.shift if @lines.first =~ /^#!/ @lines.each_index do |idx| next if @lines[idx] =~ /^\s*$/ lineno = idx + 1 + (@shebang ? 1 : 0) # Compensate for base-0 and shebang line if @lines[idx] =~ /^\s*\#/ @comments.add @lines[idx], lineno else @code.add @lines[idx], lineno end end pod_comments shell_variables end |
Instance Attribute Details
#code ⇒ Object
Contains all non-comments of the script, excluding shebang line.
Same as with comments, excluded from code blocks are only hash-comments, but here-documents even if they are not executing any action are included here.
71 72 73 |
# File 'lib/banalize/parser.rb', line 71 def code @code end |
#comments ⇒ Object
Contains all block comments of the file, excluding shebang line
Only hash-comments are suported at this time. Comments in the style of here-documents are not.
63 64 65 |
# File 'lib/banalize/parser.rb', line 63 def comments @comments end |
#lines ⇒ Object
Lines of the tested bash file, split by n‘s
47 48 49 |
# File 'lib/banalize/parser.rb', line 47 def lines @lines end |
#path ⇒ Object
UNIX path to the tested file
50 51 52 |
# File 'lib/banalize/parser.rb', line 50 def path @path end |
#shebang ⇒ Object
Shebang contains first line of the script if it’s in ‘#!` format. Otherwise it is nil.
56 57 58 |
# File 'lib/banalize/parser.rb', line 56 def shebang @shebang end |