mattfawcett-ruby-reads-php 1.0.0 → 1.1.0

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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 0
3
+ :minor: 1
4
4
  :patch: 0
@@ -19,15 +19,27 @@ class RubyReadsPHP
19
19
  end
20
20
 
21
21
  def parse_file(file)
22
- constant_regex = /define\((\s)*('|")((\w|\s)+)('|")(\s)*,(\s)*('|")?((\w|\s)*)('|")(\s)*\);/
22
+ constant_regex = /define\((\s)*('|")((\w|\s)+)('|")(\s)*,(\s)*(('|")?)([^'"]*)(('|")?)(\s)*\);/
23
23
  while (line = file.gets)
24
24
  if line.match(constant_regex)
25
25
  contant_key = line[constant_regex, 3]
26
- constant_value = line[constant_regex, 9]
26
+ constant_value = line[constant_regex, 10]
27
+ if line[constant_regex, 9].nil?
28
+ #This value was not wrapped in quotes. cast it to either an integer or a float
29
+ constant_value = cast_not_string_value(constant_value)
30
+ end
27
31
  constants[contant_key] = constant_value
28
32
  end
29
33
  end
30
34
  end
31
35
 
36
+ def cast_not_string_value(value)
37
+ if value.match(/\./)
38
+ return value.to_f
39
+ else
40
+ return value.to_i
41
+ end
42
+ end
43
+
32
44
 
33
45
  end
@@ -0,0 +1,5 @@
1
+ <?php
2
+
3
+ define('MY_CONSTANT', 95.5);
4
+
5
+ ?>
@@ -0,0 +1,5 @@
1
+ <?php
2
+
3
+ define('MY_CONSTANT', 100);
4
+
5
+ ?>
@@ -0,0 +1,5 @@
1
+ <?php
2
+
3
+ define('MY_CONSTANT', "100");
4
+
5
+ ?>
@@ -0,0 +1,5 @@
1
+ <?php
2
+
3
+ define('MY_CONSTANT', 'http://www.google.com');
4
+
5
+ ?>
@@ -22,6 +22,29 @@ describe "Ruby reads PHP" do
22
22
  rrp.constants['MY_CONSTANT'].should eql('my value')
23
23
  rrp.constants['MY_CONSTANT_NUMBER_2'].should eql('my value 2')
24
24
  end
25
+
26
+ it "should read slashes" do
27
+ rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/simple_constant_with_slashes.php")
28
+ rrp.constants['MY_CONSTANT'].should eql('http://www.google.com')
29
+ end
30
+
31
+ it "should cast as integer" do
32
+ rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/integer.php")
33
+ rrp.constants['MY_CONSTANT'].should eql(100)
34
+ end
35
+
36
+ it "should not cast as integer when quoted" do
37
+ rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/integer_quoted.php")
38
+ rrp.constants['MY_CONSTANT'].should eql("100")
39
+ end
40
+
41
+
42
+ it "should cast as float" do
43
+ rrp = RubyReadsPHP.read(File.dirname(__FILE__) + "/fixtures/float.php")
44
+ rrp.constants['MY_CONSTANT'].should eql(95.5.to_f)
45
+ end
46
+
47
+
25
48
  end
26
49
 
27
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattfawcett-ruby-reads-php
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Fawcett
@@ -27,8 +27,12 @@ files:
27
27
  - test/ruby_reads_php.spec
28
28
  - test/fixtures
29
29
  - test/fixtures/multiple_constants.php
30
+ - test/fixtures/simple_constant_with_slashes.php
30
31
  - test/fixtures/simple_constant.php
32
+ - test/fixtures/integer_quoted.php
33
+ - test/fixtures/integer.php
31
34
  - test/fixtures/simple_constant_with_double_quotes.php
35
+ - test/fixtures/float.php
32
36
  - test/fixtures/simple_constant_with_extra_spacing.php
33
37
  has_rdoc: true
34
38
  homepage: http://github.com/mattfawcett/ruby-reads-php