castic 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/castic.rb +24 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 802ec01397ff02f562d4f962018aa246549b6cbc
4
- data.tar.gz: 61d64a07cc33dda23eb69d621cf3e2de404bb737
3
+ metadata.gz: 71a3fd9478158ff682fc04943f29e3b307a702e9
4
+ data.tar.gz: 9fbcb2ed1d6895796e357ed6c7f3873a76efac78
5
5
  SHA512:
6
- metadata.gz: 80b0e4a52ffd0b531e2f9368280b1e5d065002421fb80df3a3f5964220cb0e2be806b1453a621a955fd4631b9604462895fa6b97c90dae8306aec923877f6c14
7
- data.tar.gz: 18089ba17418af4a5057a8027bc951baae417e134dff02ef59fcf5c975db33aa82c63af1e614bc4ee219e1e223ea4df032bc41dbccae245b77822611c5370ab3
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(cask)
6
- @file = cask
7
- @source = IO.read cask
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
- k = @tree.index [nil, :Cask]
26
- @tree[k-1][1].to_s
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
- k = @tree.index [nil, :Cask]
31
- body = @tree[k+1]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: castic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Saparelli