Class: Castic
- Inherits:
-
Object
- Object
- Castic
- Defined in:
- lib/castic.rb
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #class_index ⇒ Object
- #expected_name ⇒ Object
-
#initialize(file, type = :Cask) ⇒ Castic
constructor
A new instance of Castic.
- #name ⇒ Object
- #props(key = nil) ⇒ Object
Constructor Details
#initialize(file, type = :Cask) ⇒ Castic
5 6 7 8 9 10 11 |
# File 'lib/castic.rb', line 5 def initialize(file, type = :Cask) @type = type @file = file @source = IO.read file @parsed = Parser::Ruby18.parse @source @tree = @parsed.to_tree end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
13 14 15 |
# File 'lib/castic.rb', line 13 def tree @tree end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/castic.rb', line 14 def type @type end |
Instance Method Details
#class_index ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/castic.rb', line 26 def class_index if @type == :Formula return @tree[1].index [nil, @type] end @tree.index [nil, @type] end |
#expected_name ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/castic.rb', line 16 def expected_name @file.to_s .split('/') .last .split('-') .map(&:capitalize) .join .sub /\.rb$/, '' end |
#name ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/castic.rb', line 34 def name if @type == :Formula @tree[1] else @tree end[class_index-1][1].to_s end |
#props(key = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/castic.rb', line 42 def props(key = nil) body = if @type == :Formula @tree[1][class_index+1] else @tree[class_index+1] end if key body.select { |n| n[1] == key.to_sym } else body end.map { |n| n.last n.length - 1 } end |