Class: Wandbox::Compiler

Inherits:
Hash
  • Object
show all
Includes:
Iolite::Adaptor::ToLazy, Iolite::Placeholders
Defined in:
lib/wandbox/compiler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Compiler

Returns a new instance of Compiler.



11
12
13
# File 'lib/wandbox/compiler.rb', line 11

def initialize data
	data.each { |key, value| self[key] = value }
end

Class Method Details

.from_compiler_name(name) ⇒ Object



15
16
17
18
19
# File 'lib/wandbox/compiler.rb', line 15

def self.from_compiler_name name
	compiler = Wandbox.list.find_compiler name
	return nil unless compiler
	Compiler.new compiler
end

.from_json(json) ⇒ Object



21
22
23
# File 'lib/wandbox/compiler.rb', line 21

def self.from_json json
	Compiler.new JSON.parse json
end

Instance Method Details

#find_option_by_name(name) ⇒ Object



30
31
32
# File 'lib/wandbox/compiler.rb', line 30

def find_option_by_name name
	options.find &arg1["name"] == name
end

#optionsObject



25
26
27
28
# File 'lib/wandbox/compiler.rb', line 25

def options
	options = self["switches"].select &arg1["type"] == "single"
	options + self["switches"].select(&arg1["type"] == "select").map(&arg1["options"]).flatten
end

#to_stdio(enable_options = []) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wandbox/compiler.rb', line 34

def to_stdio enable_options=[]
	opts = options
	opts.reject! &arg1["display-flags"].empty?
	opts.sort_by! &arg1["name"]
	width = (opts.max_by(&arg1["name"].length) || { "name" => "" })["name"].length
	
	enable_options_s = enable_options.map(&to_l.find_option_by_name(arg1)).compact.map(&arg1["display-flags"]).join " "
<<"EOS"
[Compiler]:
#{self["display-name"]}

[Language]:
#{self["language"]}

[Version]:
#{self["version"]}

[Compiler command]:
$ #{self["display-compile-command"]}#{ " " + enable_options_s unless enable_options_s.empty?}
#{
unless opts.empty?
<<"EOS"

[Option list]:
#{"Option name".ljust width + 1} : Added extra option
#{
	opts.map { |it|
		"  #{it["name"].ljust width + 1} : #{it["display-flags"]}"
	}.join "\n"
}
EOS
end
}
EOS
end