logicle 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -1,5 +1,4 @@
1
1
  require_relative "logicle/version"
2
- require_relative "logicle/logicle"
3
2
  require_relative "logicle/simulator"
4
3
  require_relative "logicle/tgf_reader"
5
4
  require_relative "logicle/tgf_writer"
@@ -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
@@ -50,7 +50,7 @@ module Logicle
50
50
 
51
51
  private
52
52
  def validate_type(type)
53
- if LOGIC_OPERATIONS.keys.include?(type)
53
+ if LOGIC_OPERATIONS.has_key?(type)
54
54
  type
55
55
  else
56
56
  raise UnknownNodeTypeError, "Unknown node type: '#{ type }'"
@@ -6,7 +6,7 @@ module Logicle
6
6
  end
7
7
 
8
8
  def write
9
- @circuit.nodes.values.each { |node| write_node(node) }
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
- node.type.to_s.upcase
29
+ node.type.to_s.upcase
24
30
  end
25
31
  state = node.state ? "ON" : "OFF"
26
32
 
27
- @output_file.puts "#{ id } #{ type } (#{ state })"
33
+ "#{ type } (#{ state })"
28
34
  end
29
35
 
30
36
  def write_separator
@@ -1,3 +1,3 @@
1
1
  module Logicle
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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
@@ -1,3 +0,0 @@
1
- module Logicle
2
- FILE_SUFFIX = ".tgf"
3
- end