Class: Mulang::Code

Inherits:
Object
  • Object
show all
Defined in:
lib/mulang/code.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#astObject



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

#sampleObject



12
13
14
# File 'lib/mulang/code.rb', line 12

def sample
  @language.sample @content
end