hitsuji 0.2.2 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/hitsuji.rb +6 -6
- data/lib/subsystem.rb +23 -6
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c41db3b6e6ca1cb18ae1e6dcb161739641e43465f600be7d0be4bcc47cbc522
|
4
|
+
data.tar.gz: fd6960c1f691d2f24abd5b86cdef3bb0dcb180ad652229e0112a77a1554b9967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ea5f30e92347db4cd6912f249960d086e52fee378144b4e0b4d32a13197fec5b0fff60be7ebf09c9904dd0092476a472a696e7a8e297f9d8d6786385767f2b
|
7
|
+
data.tar.gz: 89491e5e7bbab1141192426e4d0ac3c200bca58d134dc63a109a48b713bd616da8f4c4298198daef993400a8a3f4e99e895e14d93e7a983f567427026f5b1a9f
|
data/lib/hitsuji.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative 'control.rb'
|
|
6
6
|
# all the functions you need. Examples using this class can be found in the
|
7
7
|
# descriptions of the class and instance methods below.
|
8
8
|
class Hitsuji
|
9
|
-
# Creates a new system
|
9
|
+
# Creates a new empty system.
|
10
10
|
#
|
11
11
|
# ==== Example
|
12
12
|
#
|
@@ -65,7 +65,7 @@ class Hitsuji
|
|
65
65
|
# * +name+ - the name of the new linker, which is written as a symbol.
|
66
66
|
# * +input+ - the contents of the new linker, whether that be an item or
|
67
67
|
# another linker.
|
68
|
-
# * +block+ - a block
|
68
|
+
# * +block+ - a block that performs the operation
|
69
69
|
#
|
70
70
|
# ==== Example
|
71
71
|
#
|
@@ -74,10 +74,10 @@ class Hitsuji
|
|
74
74
|
# my_item2 = Hitsuji.item(:qux, 2) # a second item
|
75
75
|
# items = [:foo, :qux]
|
76
76
|
# my_linker = Hitsuji.linker(:baz, items) # a new linker
|
77
|
-
# my_op = Hitsuji.operation(:op, my_linker
|
77
|
+
# my_op = Hitsuji.operation(:op, my_linker) {
|
78
78
|
# |arg1, arg2| arg1 + arg2
|
79
|
-
# }
|
80
|
-
def self.operation(name, input, block)
|
79
|
+
# } # => :foo + :qux => 1 + 2 => 3 # a new operation
|
80
|
+
def self.operation(name, input, &block)
|
81
81
|
Operation.new(name, input, block)
|
82
82
|
end
|
83
83
|
|
@@ -90,7 +90,7 @@ class Hitsuji
|
|
90
90
|
#
|
91
91
|
# ==== Attributes
|
92
92
|
#
|
93
|
-
# * +obj+ - the items, linkers and
|
93
|
+
# * +obj+ - the items, linkers and operations you want to bind
|
94
94
|
#
|
95
95
|
# ==== Example
|
96
96
|
#
|
data/lib/subsystem.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'method_source'
|
2
|
+
|
1
3
|
# The Item class is the Hitsuji representation of a variable, and its properties
|
2
4
|
# include a name and a value. The value has read-write properties, but once the
|
3
5
|
# Item is bound, a seperate method must be used to read and change it. Examples
|
@@ -29,18 +31,33 @@ end
|
|
29
31
|
# The Operation class is the Hitsuji representation of an equation, and its
|
30
32
|
# properties include a name, a value and a block. The value is an Linker with
|
31
33
|
# read-write properties, and the values in this Linker are parsed into the block
|
32
|
-
# for execution. This block is
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# documentation for the Hitsuji.operation method.
|
34
|
+
# for execution. This block is only executed upon read of dependent values. Once
|
35
|
+
# the Operation is bound, a seperate method must be used to read them. Linkers
|
36
|
+
# are the main interface between Items and Operations. Examples of its use can
|
37
|
+
# be seen in the documentation for the Hitsuji.operation method.
|
37
38
|
class Operation
|
38
39
|
def initialize(name, input, block)
|
39
40
|
@name = name
|
40
41
|
@input = input
|
41
|
-
|
42
|
+
src = MethodSource.source_helper(block.source_location)
|
43
|
+
@block = 'proc ' + src.match(/(do|\{)+?(.|\s)*(end|\})+?/).to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def call
|
47
|
+
eval(@block).call(recurse(@input.value))
|
48
|
+
end
|
49
|
+
|
50
|
+
def recurse(obj)
|
51
|
+
res = []
|
52
|
+
obj.each do |n|
|
53
|
+
res << n.value if n.class == Item
|
54
|
+
res << n.call_proc if n.class == Operation
|
55
|
+
res << recurse(n.value) if n.class == Linker
|
56
|
+
end
|
57
|
+
res
|
42
58
|
end
|
43
59
|
|
60
|
+
private :recurse
|
44
61
|
attr_reader :block
|
45
62
|
attr_accessor :name, :input
|
46
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hitsuji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Quail
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-02-07 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: method_source
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
13
27
|
description: |-
|
14
28
|
Hitsuji is a library that implements a tree data structure,
|
15
29
|
where each node is represented by a value, points to other values, or performs
|
@@ -34,7 +48,7 @@ licenses:
|
|
34
48
|
metadata:
|
35
49
|
source_code_uri: https://github.com/realtable/hitsuji
|
36
50
|
bug_tracker_uri: https://github.com/realtable/hitsuji/issues
|
37
|
-
documentation_uri: https://www.rubydoc.info/gems/hitsuji/0.
|
51
|
+
documentation_uri: https://www.rubydoc.info/gems/hitsuji/0.3.0
|
38
52
|
post_install_message:
|
39
53
|
rdoc_options: []
|
40
54
|
require_paths:
|