castic 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/castic.rb +24 -7
- 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: 71a3fd9478158ff682fc04943f29e3b307a702e9
|
4
|
+
data.tar.gz: 9fbcb2ed1d6895796e357ed6c7f3873a76efac78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b101499421df6885294bd5301228ebbc5dda253b68632dd90531db30659718c5e2d3c66f8af80014e82c6338991ae81105c6d0bb9476e026a22160ffe6bb33c7
|
7
|
+
data.tar.gz: 01cdc4de592269b46b4c2646bfbddad5d891fec80b5d671f98913b3be89660e597ab3a27c954a5834c9023126f42fc1e91d0b85be80a1943647975af988bdcce
|
data/lib/castic.rb
CHANGED
@@ -2,14 +2,16 @@ require 'parser/ruby18'
|
|
2
2
|
require_relative 'extends/parser'
|
3
3
|
|
4
4
|
class Castic
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@
|
5
|
+
def initialize(file, type = :Cask)
|
6
|
+
@type = type
|
7
|
+
@file = file
|
8
|
+
@source = IO.read file
|
8
9
|
@parsed = Parser::Ruby18.parse @source
|
9
10
|
@tree = @parsed.to_tree
|
10
11
|
end
|
11
12
|
|
12
13
|
attr_reader :tree
|
14
|
+
attr :type
|
13
15
|
|
14
16
|
def expected_name
|
15
17
|
@file.to_s
|
@@ -21,14 +23,29 @@ class Castic
|
|
21
23
|
.sub /\.rb$/, ''
|
22
24
|
end
|
23
25
|
|
26
|
+
def class_index
|
27
|
+
if @type == :Formula
|
28
|
+
return @tree[1].index [nil, @type]
|
29
|
+
end
|
30
|
+
|
31
|
+
@tree.index [nil, @type]
|
32
|
+
end
|
33
|
+
|
24
34
|
def name
|
25
|
-
|
26
|
-
|
35
|
+
if @type == :Formula
|
36
|
+
@tree[1]
|
37
|
+
else
|
38
|
+
@tree
|
39
|
+
end[class_index-1][1].to_s
|
27
40
|
end
|
28
41
|
|
29
42
|
def props(key = nil)
|
30
|
-
|
31
|
-
|
43
|
+
body = if @type == :Formula
|
44
|
+
@tree[1][class_index+1]
|
45
|
+
else
|
46
|
+
@tree[class_index+1]
|
47
|
+
end
|
48
|
+
|
32
49
|
if key
|
33
50
|
body.select { |n|
|
34
51
|
n[1] == key.to_sym
|