logicle 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/logicle +1 -1
- data/lib/logicle.rb +0 -1
- data/lib/logicle/digraph.rb +5 -6
- data/lib/logicle/node.rb +1 -1
- data/lib/logicle/tgf_writer.rb +9 -3
- data/lib/logicle/version.rb +1 -1
- metadata +1 -2
- data/lib/logicle/logicle.rb +0 -3
data/bin/logicle
CHANGED
@@ -40,10 +40,10 @@ end
|
|
40
40
|
|
41
41
|
# Evaluate the circuit.
|
42
42
|
simulator.evaluate
|
43
|
-
bulbs = simulator.outputs
|
44
43
|
|
45
44
|
|
46
45
|
# Print out the bulb states.
|
46
|
+
bulbs = simulator.outputs
|
47
47
|
bulbs.each_with_index do |bulb, i|
|
48
48
|
puts "Bulb \##{ i + 1 }: #{ bulb.state ? "on" : "off" }"
|
49
49
|
end
|
data/lib/logicle.rb
CHANGED
data/lib/logicle/digraph.rb
CHANGED
@@ -6,12 +6,6 @@ module Logicle
|
|
6
6
|
@nodes, @edges = {}, {}
|
7
7
|
end
|
8
8
|
|
9
|
-
def evaluate
|
10
|
-
outputs.each_value do |output|
|
11
|
-
output.state
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
9
|
def inputs
|
16
10
|
@nodes.select { |id, node| node.switch? }
|
17
11
|
end
|
@@ -36,6 +30,11 @@ module Logicle
|
|
36
30
|
end
|
37
31
|
end
|
38
32
|
|
33
|
+
def evaluate
|
34
|
+
outputs.each_value { |output| output.state }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
39
38
|
private
|
40
39
|
def raise_unknown_nodes(node_map={})
|
41
40
|
bad_node_ids = node_map.select { |id, node| node.nil? }.keys
|
data/lib/logicle/node.rb
CHANGED
data/lib/logicle/tgf_writer.rb
CHANGED
@@ -6,7 +6,7 @@ module Logicle
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def write
|
9
|
-
@circuit.nodes.
|
9
|
+
@circuit.nodes.each_value { |node| write_node(node) }
|
10
10
|
|
11
11
|
write_separator
|
12
12
|
|
@@ -16,15 +16,21 @@ module Logicle
|
|
16
16
|
private
|
17
17
|
def write_node(node)
|
18
18
|
id = node.id
|
19
|
+
label = format_label(node)
|
20
|
+
|
21
|
+
@output_file.puts "#{ id } #{ label }"
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_label(node)
|
19
25
|
type = case node.type
|
20
26
|
when :on, :off
|
21
27
|
"SWITCH"
|
22
28
|
else
|
23
|
-
|
29
|
+
node.type.to_s.upcase
|
24
30
|
end
|
25
31
|
state = node.state ? "ON" : "OFF"
|
26
32
|
|
27
|
-
|
33
|
+
"#{ type } (#{ state })"
|
28
34
|
end
|
29
35
|
|
30
36
|
def write_separator
|
data/lib/logicle/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logicle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -30,7 +30,6 @@ files:
|
|
30
30
|
- examples/simple_solved.tgf
|
31
31
|
- lib/logicle.rb
|
32
32
|
- lib/logicle/digraph.rb
|
33
|
-
- lib/logicle/logicle.rb
|
34
33
|
- lib/logicle/node.rb
|
35
34
|
- lib/logicle/simulator.rb
|
36
35
|
- lib/logicle/tgf_reader.rb
|
data/lib/logicle/logicle.rb
DELETED