Class: RubyReadsPHP
- Inherits:
-
Object
- Object
- RubyReadsPHP
- Defined in:
- lib/ruby_reads_php.rb
Instance Attribute Summary collapse
-
#constants ⇒ Object
Returns the value of attribute constants.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ RubyReadsPHP
constructor
A new instance of RubyReadsPHP.
- #parse(file_name) ⇒ Object
- #parse_file(file) ⇒ Object
Constructor Details
#initialize ⇒ RubyReadsPHP
Returns a new instance of RubyReadsPHP.
4 5 6 |
# File 'lib/ruby_reads_php.rb', line 4 def initialize self.constants = {} end |
Instance Attribute Details
#constants ⇒ Object
Returns the value of attribute constants.
2 3 4 |
# File 'lib/ruby_reads_php.rb', line 2 def constants @constants end |
Class Method Details
.read(file_name) ⇒ Object
8 9 10 11 |
# File 'lib/ruby_reads_php.rb', line 8 def self.read(file_name) rrp = self.new rrp.parse(file_name) end |
Instance Method Details
#parse(file_name) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ruby_reads_php.rb', line 14 def parse(file_name) file_name << '.php' unless file_name.match(/.php/) file = File.new(file_name, "r") data = parse_file(file) self end |
#parse_file(file) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_reads_php.rb', line 21 def parse_file(file) constant_regex = /define\((\s)*('|")((\w|\s)+)('|")(\s)*,(\s)*('|")?((\w|\s)*)('|")(\s)*\);/ while (line = file.gets) if line.match(constant_regex) contant_key = line[constant_regex, 3] constant_value = line[constant_regex, 9] constants[contant_key] = constant_value end end end |