Class: Rubrowser::Parser::File
- Inherits:
-
Object
- Object
- Rubrowser::Parser::File
- Defined in:
- lib/parser/file.rb
Constant Summary collapse
- FILE_SIZE_LIMIT =
2 * 1024 * 1024
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#occurences ⇒ Object
readonly
Returns the value of attribute occurences.
Instance Method Summary collapse
- #count ⇒ Object
- #file_valid?(file) ⇒ Boolean
-
#initialize(file) ⇒ File
constructor
A new instance of File.
- #parse ⇒ Object
Constructor Details
#initialize(file) ⇒ File
Returns a new instance of File.
10 11 12 13 14 |
# File 'lib/parser/file.rb', line 10 def initialize(file) @file = file @definitions = Set.new @occurences = [] end |
Instance Attribute Details
#definitions ⇒ Object
Returns the value of attribute definitions.
8 9 10 |
# File 'lib/parser/file.rb', line 8 def definitions @definitions end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/parser/file.rb', line 8 def file @file end |
#occurences ⇒ Object
Returns the value of attribute occurences.
8 9 10 |
# File 'lib/parser/file.rb', line 8 def occurences @occurences end |
Instance Method Details
#count ⇒ Object
33 34 35 |
# File 'lib/parser/file.rb', line 33 def count 1 end |
#file_valid?(file) ⇒ Boolean
29 30 31 |
# File 'lib/parser/file.rb', line 29 def file_valid?(file) !::File.symlink?(file) && ::File.file?(file) && ::File.size(file) <= FILE_SIZE_LIMIT end |
#parse ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/parser/file.rb', line 16 def parse if file_valid?(file) ::File.open(file) do |f| code = f.read ast = ::Parser::CurrentRuby.parse(code) constants = parse_block(ast) self.definitions = constants[:definitions].uniq self.occurences = constants[:occurences].uniq end end self end |