code_analyzer 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/code_analyzer/sexp.rb +22 -7
- data/lib/code_analyzer/version.rb +1 -1
- data/spec/code_analyzer/sexp_spec.rb +7 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53fb6c883111cef067134b5b5fe328791ae6ccd9
|
4
|
+
data.tar.gz: 0fb961476a2a02aac6ecb2d43a3dc7c08fb9d5e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f0f07ebcd584a6747d1320a60ee7ce72e1fdd21e452b8a20df1d269f8c8596cbf8a0a14152723d2a27c1c40bcb92a8b7c2f657f120f9a1450d801277f5b87f
|
7
|
+
data.tar.gz: 2c843a87027189ebc42acecbcefd6c92aba0078ed66cdb2a3e71fa9a474db1ff4179e927d18f9631674be6d57755c23c2507ab5fd8f5d320b913b7d67c9d3028
|
data/lib/code_analyzer/sexp.rb
CHANGED
@@ -735,15 +735,30 @@ class Sexp
|
|
735
735
|
#
|
736
736
|
# @return [Array] array values
|
737
737
|
def array_values
|
738
|
-
|
738
|
+
case sexp_type
|
739
|
+
when :array
|
739
740
|
if nil == self[1]
|
740
741
|
[]
|
742
|
+
elsif :words_add == self[1].sexp_type
|
743
|
+
self[1].array_values
|
741
744
|
elsif :qwords_add == self[1].sexp_type
|
742
745
|
self[1].array_values
|
743
746
|
else
|
744
747
|
arguments.all
|
745
748
|
end
|
746
|
-
|
749
|
+
when :words_add
|
750
|
+
values = []
|
751
|
+
node = self
|
752
|
+
while true
|
753
|
+
if :words_add == node.sexp_type
|
754
|
+
values.unshift node[2]
|
755
|
+
node = node[1]
|
756
|
+
elsif :words_new == node.sexp_type
|
757
|
+
break
|
758
|
+
end
|
759
|
+
end
|
760
|
+
values
|
761
|
+
when :qwords_add
|
747
762
|
values = []
|
748
763
|
node = self
|
749
764
|
while true
|
@@ -755,6 +770,8 @@ class Sexp
|
|
755
770
|
end
|
756
771
|
end
|
757
772
|
values
|
773
|
+
else
|
774
|
+
[]
|
758
775
|
end
|
759
776
|
end
|
760
777
|
|
@@ -822,11 +839,9 @@ class Sexp
|
|
822
839
|
self[1].to_s
|
823
840
|
end
|
824
841
|
when :qwords_add
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
self[1].to_s
|
829
|
-
end
|
842
|
+
self[2].to_s
|
843
|
+
when :word_add
|
844
|
+
self[2].to_s
|
830
845
|
when :const_path_ref
|
831
846
|
"#{self[1]}::#{self[2]}"
|
832
847
|
when :@label
|
@@ -558,8 +558,13 @@ describe Sexp do
|
|
558
558
|
node.array_values.should == []
|
559
559
|
end
|
560
560
|
|
561
|
-
it "should get array value with
|
562
|
-
node = parse_content("%
|
561
|
+
it "should get array value with array and words_add" do
|
562
|
+
node = parse_content("%W{day week fortnight}").grep_node(sexp_type: :array)
|
563
|
+
node.array_values.map(&:to_s).should == ["day", "week", "fortnight"]
|
564
|
+
end
|
565
|
+
|
566
|
+
it "should get array value with array and qwords_add" do
|
567
|
+
node = parse_content("%w(first_name last_name)").grep_node(sexp_type: :array)
|
563
568
|
node.array_values.map(&:to_s).should == ["first_name", "last_name"]
|
564
569
|
end
|
565
570
|
end
|