Class: Castic
- Inherits:
-
Object
- Object
- Castic
- Defined in:
- lib/castic.rb
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #expected_name ⇒ Object
-
#initialize(cask) ⇒ Castic
constructor
A new instance of Castic.
- #name ⇒ Object
- #props(key = nil) ⇒ Object
Constructor Details
#initialize(cask) ⇒ Castic
Returns a new instance of Castic.
5 6 7 8 9 10 |
# File 'lib/castic.rb', line 5 def initialize(cask) @file = cask @source = IO.read cask @parsed = Parser::Ruby18.parse @source @tree = @parsed.to_tree end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
12 13 14 |
# File 'lib/castic.rb', line 12 def tree @tree end |
Instance Method Details
#expected_name ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/castic.rb', line 14 def expected_name @file.to_s .split('/') .last .split('-') .map(&:capitalize) .join .sub /\.rb$/, '' end |
#name ⇒ Object
24 25 26 27 |
# File 'lib/castic.rb', line 24 def name k = @tree.index [nil, :Cask] @tree[k-1][1].to_s end |
#props(key = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/castic.rb', line 29 def props(key = nil) k = @tree.index [nil, :Cask] body = @tree[k+1] if key body.select { |n| n[1] == key.to_sym } else body end.map { |n| n.last n.length - 1 } end |