hitsuji 0.0.2 → 0.1.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 +167 -65
- data/lib/subsystem.rb +28 -23
- data/lib/transfer.rb +4 -6
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8684d26a3c885f06c3f570392bf3b4d9f3ba2a53140c79042cf3073c58a17d94
|
4
|
+
data.tar.gz: 6b7ab355bccb09ce0e1ce2568f191a5992f351f930cb618adfae2a01418591a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4222f6f121cbacc71d9ce4969e91af4c83fc4c90b812b8698c0858a818b15f6696f6b4ce75969db075c16e49e4d94783523c49eae1ae4ca0289c945c0a16155f
|
7
|
+
data.tar.gz: f39cf1230837d28feb00b9241d012ba6ce26ea47e70ddb262348e8d4b935e7869d45caadeba0f393a7d495ab4de028886d34a1805d0ec1cdb74d984624285b67
|
data/lib/hitsuji.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# * Hitsuji
|
2
|
-
|
3
1
|
require 'transfer'
|
4
2
|
require 'subsystem'
|
5
3
|
|
4
|
+
# The Hitsuji class is the interface to this module, and it contains
|
5
|
+
# all the functions you need. Examples using this class can be found in the
|
6
|
+
# descriptions of the class and instance methods below.
|
6
7
|
class Hitsuji
|
7
|
-
|
8
|
-
# Creates a new system where all operations can be performed.
|
8
|
+
# Creates a new system where all operations are performed.
|
9
9
|
#
|
10
10
|
# ==== Example
|
11
11
|
#
|
@@ -13,99 +13,97 @@ class Hitsuji
|
|
13
13
|
def initialize
|
14
14
|
@struct = []
|
15
15
|
end
|
16
|
-
|
17
|
-
# Creates a new item, the equivalent of a variable in the system.
|
18
|
-
# declared, the value of an item can be changed but not the name. No item
|
19
|
-
# is allowed to share the same name as any other.
|
16
|
+
|
17
|
+
# Creates a new item, the equivalent of a variable in the system.
|
20
18
|
#
|
21
19
|
# ==== Attributes
|
22
20
|
#
|
23
21
|
# * +name+ - the name of the new item, which is written as a symbol.
|
24
|
-
# * +value+ - the contents of the new item, whether that be a string,
|
22
|
+
# * +value+ - the contents of the new item, whether that be a string,
|
25
23
|
# variable or any other object.
|
26
24
|
#
|
27
25
|
# ==== Example
|
28
26
|
#
|
29
27
|
# my_system = Hitsuji.new # a new system
|
30
|
-
# my_item =
|
31
|
-
def item(name, value)
|
32
|
-
|
33
|
-
return new_item
|
28
|
+
# my_item = Hitsuji.item(:foo, 'bar') # a new item
|
29
|
+
def self.item(name, value)
|
30
|
+
Item.new(name, value)
|
34
31
|
end
|
35
|
-
|
32
|
+
|
36
33
|
# Creates a new linker, which is simply put a grouping of items and other
|
37
|
-
# linkers.
|
38
|
-
# must not share its name with any other linker, or item for that matter.
|
34
|
+
# linkers.
|
39
35
|
#
|
40
36
|
# ==== Attributes
|
41
37
|
#
|
42
38
|
# * +name+ - the name of the new linker, which is written as a symbol.
|
43
|
-
# * +value+ - the contents of the new linker, whether that be an item or
|
39
|
+
# * +value+ - the contents of the new linker, whether that be an item or
|
44
40
|
# another linker.
|
45
41
|
#
|
46
42
|
# ==== Example
|
47
43
|
#
|
48
44
|
# my_system = Hitsuji.new # a new system
|
49
|
-
# my_item =
|
50
|
-
# my_item2 =
|
45
|
+
# my_item = Hitsuji.item(:foo, 'bar') # a new item
|
46
|
+
# my_item2 = Hitsuji.item(:qux, 'quux') # a second item
|
51
47
|
# items = [:foo, :qux]
|
52
|
-
# my_linker =
|
53
|
-
def linker(name, objs)
|
54
|
-
|
55
|
-
return new_linker
|
48
|
+
# my_linker = Hitsuji.linker(:baz, items) # a new linker
|
49
|
+
def self.linker(name, objs)
|
50
|
+
Linker.new(name, objs)
|
56
51
|
end
|
57
|
-
|
58
|
-
# Creates a new operation, which is an
|
52
|
+
|
53
|
+
# Creates a new operation, which is an equation performed on multiple items
|
59
54
|
# contained within a linker. This linker can contain more linkers from which
|
60
|
-
# more items will be progressively taken. An operation can then be used as
|
55
|
+
# more items will be progressively taken. An operation can then be used as
|
61
56
|
# part of a linker, and the result can be used in another operation.
|
62
57
|
#
|
63
58
|
# ==== Attributes
|
64
59
|
#
|
65
60
|
# * +name+ - the name of the new linker, which is written as a symbol.
|
66
|
-
# * +input+ - the contents of the new linker, whether that be an item or
|
61
|
+
# * +input+ - the contents of the new linker, whether that be an item or
|
67
62
|
# another linker.
|
68
63
|
# * +block+ - a block as a string to perform the operation
|
69
64
|
#
|
70
65
|
# ==== Example
|
71
66
|
#
|
72
67
|
# my_system = Hitsuji.new # a new system
|
73
|
-
# my_item =
|
74
|
-
# my_item2 =
|
68
|
+
# my_item = Hitsuji.item(:foo, 1) # a new item
|
69
|
+
# my_item2 = Hitsuji.item(:qux, 2) # a second item
|
75
70
|
# items = [:foo, :qux]
|
76
|
-
# my_linker =
|
77
|
-
# my_op =
|
71
|
+
# my_linker = Hitsuji.linker(:baz, items) # a new linker
|
72
|
+
# my_op = Hitsuji.operation(:op, my_linker, %{ # a new operation
|
78
73
|
# |arg1, arg2| arg1 + arg2
|
79
74
|
# }) # => :foo + :qux => 1 + 2 => 3
|
80
|
-
def operation(name, input, block)
|
81
|
-
|
82
|
-
return new_operation
|
75
|
+
def self.operation(name, input, block)
|
76
|
+
Operation.new(name, input, block)
|
83
77
|
end
|
84
|
-
|
85
|
-
# Binds the inputted items to the system, allowing for the continous
|
86
|
-
# of the values within a system. This continuous updating
|
87
|
-
# Hitsuji
|
78
|
+
|
79
|
+
# 'Binds' the inputted items to the system, allowing for the continous
|
80
|
+
# updating of the values within a system. This continuous updating forms the
|
81
|
+
# main principle of Hitsuji. Once bound, an object can only be edited using
|
82
|
+
# the Hitsuji.find, Hitsuji.edit and Hitsuji.remove methods. It can never
|
83
|
+
# share a name with any other bound object. Once bound, the name of an object
|
84
|
+
# becomes uneditable, but the value still keeps its read-write capabilites.
|
88
85
|
#
|
89
86
|
# ==== Attributes
|
90
87
|
#
|
91
|
-
# *
|
88
|
+
# * +obj+ - the items, linkers and operation you want to bind
|
92
89
|
#
|
93
90
|
# ==== Example
|
94
91
|
#
|
95
92
|
# my_system = Hitsuji.new # a new system
|
96
|
-
# my_item =
|
97
|
-
# my_item2 =
|
93
|
+
# my_item = Hitsuji.item(:foo, 1) # a new item
|
94
|
+
# my_item2 = Hitsuji.item(:qux, 2) # a second item
|
98
95
|
# items = [:foo, :qux]
|
99
|
-
# my_linker =
|
96
|
+
# my_linker = Hitsuji.linker(:baz, items) # a new linker
|
100
97
|
# my_system.bind(my_item, my_item2, my_linker) # binds items + linker
|
101
98
|
def bind(*obj)
|
102
99
|
@struct.concat obj
|
103
|
-
|
100
|
+
update @struct
|
104
101
|
end
|
105
|
-
|
106
|
-
# Exports current state of system to a file. This process
|
107
|
-
# unbound items, linkers or operations!
|
108
|
-
#
|
102
|
+
|
103
|
+
# Exports the current state of the system to a file. This process *does not*
|
104
|
+
# export unbound items, linkers or operations! Creating new items doesn't
|
105
|
+
# automatically bind them to the system, so therefore the exported file
|
106
|
+
# only contains objects bound with Hitsuji.bind.
|
109
107
|
#
|
110
108
|
# ==== Attributes
|
111
109
|
#
|
@@ -115,15 +113,15 @@ class Hitsuji
|
|
115
113
|
# ==== Example
|
116
114
|
#
|
117
115
|
# my_system = Hitsuji.new # a new system
|
118
|
-
# my_item =
|
116
|
+
# my_item = Hitsuji.item(:foo, 1) # a new item
|
119
117
|
# my_system.bind(my_item) # binds item
|
120
118
|
# my_system.export('newfile.txt') # exports to 'newfile.txt'
|
121
119
|
def export(directory)
|
122
120
|
Transfer.export(directory, @struct)
|
123
121
|
end
|
124
|
-
|
125
|
-
# Imports file into a system,
|
126
|
-
#
|
122
|
+
|
123
|
+
# Imports a file into a system, *overwriting anything already bound to the
|
124
|
+
# system*.
|
127
125
|
#
|
128
126
|
# ==== Attributes
|
129
127
|
#
|
@@ -132,23 +130,127 @@ class Hitsuji
|
|
132
130
|
# ==== Example
|
133
131
|
#
|
134
132
|
# my_system = Hitsuji.new # a new system
|
135
|
-
# my_system.import('oldfile.txt') # imports
|
133
|
+
# my_system.import('oldfile.txt') # imports 'oldfile.txt'
|
136
134
|
def import(directory)
|
137
135
|
@struct = Transfer.import(directory)
|
138
|
-
|
136
|
+
update @struct
|
139
137
|
end
|
140
138
|
|
141
|
-
|
139
|
+
# Finds a bound object in the system by name, and returns the object if it
|
140
|
+
# exists.
|
141
|
+
#
|
142
|
+
# ==== Attributes
|
143
|
+
#
|
144
|
+
# * +query+ - the name of the object to search for
|
145
|
+
#
|
146
|
+
# ==== Example
|
147
|
+
#
|
148
|
+
# my_system = Hitsuji.new # a new system
|
149
|
+
# my_system.import('oldfile.txt') # imports 'oldfile.txt'
|
150
|
+
# my_item = my_system.find(:foo) # finds an item
|
151
|
+
def find(query)
|
152
|
+
get(query, @struct, nil, false)
|
153
|
+
end
|
142
154
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
155
|
+
# Finds a bound object in the system by name, edits the object if it exists,
|
156
|
+
# and then returns the original object.
|
157
|
+
#
|
158
|
+
# ==== Attributes
|
159
|
+
#
|
160
|
+
# * +query+ - the name of the object to edit
|
161
|
+
# * +value+ - the new value to assign to this object
|
162
|
+
#
|
163
|
+
# ==== Example
|
164
|
+
#
|
165
|
+
# my_system = Hitsuji.new # a new system
|
166
|
+
# my_system.import('oldfile.txt') # imports 'oldfile.txt'
|
167
|
+
# my_item = my_system.edit(:foo, 'bar') # changes an item
|
168
|
+
def edit(query, value)
|
169
|
+
get(query, @struct, value, false)
|
152
170
|
end
|
153
|
-
|
154
|
-
|
171
|
+
|
172
|
+
# Finds a bound object in the system by name, removes it if it exists, and
|
173
|
+
# then returns the original object.
|
174
|
+
#
|
175
|
+
# ==== Attributes
|
176
|
+
#
|
177
|
+
# * +query+ - the name of the object to remove
|
178
|
+
#
|
179
|
+
# ==== Example
|
180
|
+
#
|
181
|
+
# my_system = Hitsuji.new # a new system
|
182
|
+
# my_system.import('oldfile.txt') # imports 'oldfile.txt'
|
183
|
+
# my_item = my_system.remove(:foo) # removes an item
|
184
|
+
def remove(query)
|
185
|
+
get(query, @struct, nil, true)
|
186
|
+
end
|
187
|
+
|
188
|
+
#--
|
189
|
+
# BEGINNING OF PRIVATE FUNCTIONS
|
190
|
+
#++
|
191
|
+
|
192
|
+
# Updates state of system to monitor name usageand dependencies on operations.
|
193
|
+
# This is run every time Hitsuji.bind or Hitsuji.import is run.
|
194
|
+
#
|
195
|
+
# ==== Attributes
|
196
|
+
#
|
197
|
+
# * +obj+ - the object to update (usually @struct)
|
198
|
+
#
|
199
|
+
# ==== Example
|
200
|
+
#
|
201
|
+
# class MyHitsuji < Hitsuji # creates dependent class
|
202
|
+
# def linker_update # my new special function!
|
203
|
+
# @struct.each do |i|
|
204
|
+
# update(@struct) if i.class == Linker # uses update function
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
# end
|
208
|
+
def update(obj)
|
209
|
+
names = []
|
210
|
+
obj.each do |i|
|
211
|
+
throw 'err' unless i.name.nil? || !names.include?(i.name)
|
212
|
+
names << update(i.value) if i.class == Linker
|
213
|
+
end
|
214
|
+
names
|
215
|
+
end
|
216
|
+
|
217
|
+
# Gets value of item from @struct and returns it. It can perform additional
|
218
|
+
# operations such as editing and removal.
|
219
|
+
#
|
220
|
+
# ==== Attributes
|
221
|
+
#
|
222
|
+
# * +query+ - the name of the object to perform the actions on
|
223
|
+
# * +obj+ - the object to search in (usually @struct)
|
224
|
+
# * +edit+ - the edit to make to the object (nil if not)
|
225
|
+
# * +remove+ - whether to remove the object (false if not)
|
226
|
+
#
|
227
|
+
# ==== Example
|
228
|
+
#
|
229
|
+
# class MyHitsuji < Hitsuji # creates dependent class
|
230
|
+
# def remove_from_linkers(query) # my new special function!
|
231
|
+
# @struct.each do |i|
|
232
|
+
# if i.class == Linker
|
233
|
+
# get(query, @struct, nil, true) # uses get function
|
234
|
+
# end
|
235
|
+
# end
|
236
|
+
# end
|
237
|
+
# end
|
238
|
+
def get(query, obj, edit, remove) # :nodoc:
|
239
|
+
answer = nil
|
240
|
+
obj.each do |i|
|
241
|
+
if i.name == query
|
242
|
+
answer = i
|
243
|
+
if edit
|
244
|
+
i.value = edit
|
245
|
+
elsif remove
|
246
|
+
i.name = nil
|
247
|
+
end
|
248
|
+
elsif i.class == Linker
|
249
|
+
answer = view(query, i.value, edit, remove)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
answer
|
253
|
+
end
|
254
|
+
|
255
|
+
private :update, :get
|
256
|
+
end
|
data/lib/subsystem.rb
CHANGED
@@ -1,41 +1,46 @@
|
|
1
|
+
# The Item class is the Hitsuji representation of a variable, and its properties
|
2
|
+
# include a name and a value. The value has read-write properties, but once the
|
3
|
+
# Item is bound, a seperate method must be used to read and change it. Examples
|
4
|
+
# of its use can be seen in the documentation for the Hitsuji.item method.
|
1
5
|
class Item
|
2
|
-
|
3
6
|
def initialize(name, value) # :nodoc:
|
4
7
|
@name = name
|
5
8
|
@value = value
|
6
9
|
end
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :value
|
10
|
-
|
10
|
+
|
11
|
+
attr_accessor :name, :value
|
11
12
|
end
|
12
13
|
|
14
|
+
# The Linker class is the Hitsuji representation of an array, and its properties
|
15
|
+
# include a name and a value. The value is an array with read-write properties,
|
16
|
+
# but once the Linker is bound, a seperate method must be used to read and
|
17
|
+
# change it. Linkers are the main interface between Items and Operations.
|
18
|
+
# Examples of its use can be seen in the documentation for the Hitsuji.linker
|
19
|
+
# method.
|
13
20
|
class Linker
|
14
|
-
|
15
21
|
def initialize(name, value) # :nodoc:
|
16
|
-
#value.each do |i|
|
17
|
-
# if i.class != Linker and i.class != Item
|
18
|
-
# throw 'err'
|
19
|
-
# end
|
20
|
-
#end
|
21
|
-
|
22
22
|
@name = name
|
23
23
|
@value = value
|
24
24
|
end
|
25
|
-
|
26
|
-
|
27
|
-
attr_accessor :value
|
28
|
-
|
25
|
+
|
26
|
+
attr_accessor :name, :value
|
29
27
|
end
|
30
28
|
|
29
|
+
# The Operation class is the Hitsuji representation of an equation, and its
|
30
|
+
# properties include a name, a value and a block. The value is an Linker with
|
31
|
+
# read-write properties, and the values in this Linker are parsed into the block
|
32
|
+
# for execution. This block is not presented as block however, but as a string,
|
33
|
+
# only executed upon read of dependent values. Once the Operation is bound, a
|
34
|
+
# seperate method must be used to read them. Linkers are the main interface
|
35
|
+
# between Items and Operations. Examples of its use can be seen in the
|
36
|
+
# documentation for the Hitsuji.operation method.
|
31
37
|
class Operation
|
32
|
-
|
33
|
-
|
34
|
-
@name = name
|
38
|
+
def initialize(name, input, block) # :nodoc:
|
39
|
+
@name = name
|
35
40
|
@input = input
|
36
41
|
@block = block
|
37
42
|
end
|
38
|
-
|
39
|
-
attr_reader :
|
40
|
-
|
41
|
-
end
|
43
|
+
|
44
|
+
attr_reader :block
|
45
|
+
attr_accessor :name, :input
|
46
|
+
end
|
data/lib/transfer.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'subsystem'
|
2
2
|
|
3
3
|
class Transfer # :nodoc:
|
4
|
-
|
5
4
|
def self.export(directory, struct)
|
6
|
-
File.open(directory,
|
5
|
+
File.open(directory, 'w') { |file| file.write(Marshal.dump(struct)) }
|
7
6
|
end
|
8
|
-
|
7
|
+
|
9
8
|
def self.import(directory)
|
10
|
-
File.open(directory,
|
9
|
+
File.open(directory, 'r') { |file| return Marshal.load(file.read) }
|
11
10
|
end
|
12
|
-
|
13
|
-
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hitsuji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Quail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
13
|
+
description: |-
|
14
|
+
Hitsuji is a library that lets you easily create, edit,
|
15
|
+
manage and apply custom management systems. It is scalable from library card
|
16
|
+
databases to performance analysis all the way to complete content management
|
17
|
+
systems (like Wordpress.com).
|
16
18
|
email: josh@madbean.com
|
17
19
|
executables: []
|
18
20
|
extensions: []
|
@@ -25,8 +27,9 @@ homepage: http://rubygems.org/gems/hitsuji
|
|
25
27
|
licenses:
|
26
28
|
- MIT
|
27
29
|
metadata:
|
30
|
+
source_code_uri: https://github.com/realtable/hitsuji
|
28
31
|
bug_tracker_uri: https://github.com/realtable/hitsuji/issues
|
29
|
-
documentation_uri: https://
|
32
|
+
documentation_uri: https://www.rubydoc.info/gems/hitsuji
|
30
33
|
post_install_message:
|
31
34
|
rdoc_options: []
|
32
35
|
require_paths:
|
@@ -35,7 +38,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
38
|
requirements:
|
36
39
|
- - ">="
|
37
40
|
- !ruby/object:Gem::Version
|
38
|
-
version: 2.
|
41
|
+
version: 2.2.0
|
39
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
43
|
requirements:
|
41
44
|
- - ">="
|