Class: Mulang::Code
- Inherits:
-
Object
- Object
- Mulang::Code
- Defined in:
- lib/mulang/code.rb
Class Method Summary collapse
- .ast(ast) ⇒ Object
- .external(content, &tool) ⇒ Object
- .native(language_name, content) ⇒ Object
- .native!(*args) ⇒ Object
Instance Method Summary collapse
- #analyse(spec) ⇒ Object
- #analysis(spec) ⇒ Object
- #ast ⇒ Object
- #custom_expect(edl) ⇒ Object (also: #custom_query)
- #expect(binding = '*', inspection) ⇒ Object (also: #query)
-
#initialize(language, content) ⇒ Code
constructor
A new instance of Code.
- #sample ⇒ Object
Constructor Details
#initialize(language, content) ⇒ Code
Returns a new instance of Code.
3 4 5 6 |
# File 'lib/mulang/code.rb', line 3 def initialize(language, content) @language = language @content = content end |
Class Method Details
.ast(ast) ⇒ Object
50 51 52 |
# File 'lib/mulang/code.rb', line 50 def self.ast(ast) new Mulang::Language::External.new, ast end |
.external(content, &tool) ⇒ Object
46 47 48 |
# File 'lib/mulang/code.rb', line 46 def self.external(content, &tool) new Mulang::Language::External.new(&tool), content end |
.native(language_name, content) ⇒ Object
38 39 40 |
# File 'lib/mulang/code.rb', line 38 def self.native(language_name, content) new Mulang::Language::Native.new(language_name), content end |
.native!(*args) ⇒ Object
42 43 44 |
# File 'lib/mulang/code.rb', line 42 def self.native!(*args) native(*args).tap { |it| it.expect('Parses') } end |
Instance Method Details
#analyse(spec) ⇒ Object
20 21 22 |
# File 'lib/mulang/code.rb', line 20 def analyse(spec) Mulang.analyse analysis(spec) end |
#analysis(spec) ⇒ Object
16 17 18 |
# File 'lib/mulang/code.rb', line 16 def analysis(spec) { sample: sample, spec: spec } end |
#ast ⇒ Object
8 9 10 |
# File 'lib/mulang/code.rb', line 8 def ast @language.ast @content end |
#custom_expect(edl) ⇒ Object Also known as: custom_query
29 30 31 32 33 |
# File 'lib/mulang/code.rb', line 29 def custom_expect(edl) expectation_results_for(analyse(customExpectations: edl)) .map { |e| [e['expectation']['inspection'], e['result']] } .to_h end |
#expect(binding = '*', inspection) ⇒ Object Also known as: query
24 25 26 27 |
# File 'lib/mulang/code.rb', line 24 def expect(binding='*', inspection) expectation = Mulang::Expectation.parse(binding: binding, inspection: inspection).as_v2.to_h expectation_results_for(analyse(expectations: [expectation])).first['result'] end |
#sample ⇒ Object
12 13 14 |
# File 'lib/mulang/code.rb', line 12 def sample @language.sample @content end |