hitsuji 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hitsuji.rb +131 -33
  3. data/lib/subsystem.rb +11 -14
  4. data/lib/transfer.rb +13 -0
  5. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b59ef71008c412ae5baac5f4102b703af2db8194a22e37a41d310f03168429b
4
- data.tar.gz: 910c6bafc9d69d0a91382d5b85d7f699f14f8b9d6b76c911102cb95d35cc53f0
3
+ metadata.gz: 94745b6c358fa83b41f7b1e1b1094099bc034c7635d5317a028dab2450f322e6
4
+ data.tar.gz: 7b4043d9e1052a589cbd76b9ef14f6bbd4da54733b7bb0ee44b77142fd047482
5
5
  SHA512:
6
- metadata.gz: 01ba139869c7119f08a332b66eee162ee6b4c7dbb59eeb141c4f31b2562e32f3cce3490cedf0a005634d4209b4e34bf91c62bff475074dd1ab7ab801724324a0
7
- data.tar.gz: bb8521f46c58ad18e0b18e31239d37c60488688e33dd0a52aca038a530324db48493da1521374f6d2fce073adba964598fc864cac237f381e860c1093deb5f08
6
+ metadata.gz: 58db3991afa8db1729c00942beb816205b114aa790114fc556417bf08350e9173df603e4758367eb5355e7ca16bb2d99d7594e622f27208db6d5ed5a609510aa
7
+ data.tar.gz: d9c9578f7e4548b95602833df86a93c8cb529a0191b51e72cce51aa46f95b4fa0fd178ec44f2cdb38788600c0b915b2cfb42795945dd7c417f9fb84f2396cf0a
data/lib/hitsuji.rb CHANGED
@@ -1,56 +1,154 @@
1
- # -- hitsuji.rb --
2
- # Main interface for hitsuji module
1
+ # * Hitsuji
3
2
 
4
- #require_relative 'transfer.rb'
5
- require_relative 'subsystem.rb'
3
+ require 'transfer'
4
+ require 'subsystem'
6
5
 
7
6
  class Hitsuji
8
7
 
9
- # creates new system
8
+ # Creates a new system where all operations can be performed.
9
+ #
10
+ # ==== Example
11
+ #
12
+ # my_system = Hitsuji.new
10
13
  def initialize
11
14
  @struct = []
12
- @used_names = []
13
15
  end
14
16
 
15
- # creates new unbinded item
17
+ # Creates a new item, the equivalent of a variable in the system. Once
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.
20
+ #
21
+ # ==== Attributes
22
+ #
23
+ # * +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,
25
+ # variable or any other object.
26
+ #
27
+ # ==== Example
28
+ #
29
+ # my_system = Hitsuji.new # a new system
30
+ # my_item = my_system.item(:foo, 'bar') # a new item
16
31
  def item(name, value)
17
- if @used_names.include? name
18
- throw 'err'
19
- else
20
- new_item = Item.new(name, value)
21
- @used_names << name
22
- end
32
+ new_item = Item.new(name, value)
23
33
  return new_item
24
34
  end
25
35
 
26
- # creates new unbinded linker
36
+ # Creates a new linker, which is simply put a grouping of items and other
37
+ # linkers. Like an item, the value is changeable but the name is not, and it
38
+ # must not share its name with any other linker, or item for that matter.
39
+ #
40
+ # ==== Attributes
41
+ #
42
+ # * +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
44
+ # another linker.
45
+ #
46
+ # ==== Example
47
+ #
48
+ # my_system = Hitsuji.new # a new system
49
+ # my_item = my_system.item(:foo, 'bar') # a new item
50
+ # my_item2 = my_system.item(:qux, 'quux') # a second item
51
+ # items = [:foo, :qux]
52
+ # my_linker = my_system.linker(:baz, items) # a new linker
27
53
  def linker(name, objs)
28
- if @used_names.include? name
29
- throw 'err'
30
- else
31
- new_linker = Linker.new(name, objs)
32
- @used_names << name
33
- end
54
+ new_linker = Linker.new(name, objs)
34
55
  return new_linker
35
56
  end
36
57
 
37
- # creates new unbined operation
38
- def operation(name, input)
39
- if @used_names.include? name
40
- throw 'err'
41
- else
42
- new_operation = Operation.new(name, input) do
43
- yield
44
- end
45
- @used_names << name
46
- end
58
+ # Creates a new operation, which is an operation performed on multiple items
59
+ # 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
61
+ # part of a linker, and the result can be used in another operation.
62
+ #
63
+ # ==== Attributes
64
+ #
65
+ # * +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
67
+ # another linker.
68
+ # * +block+ - a block as a string to perform the operation
69
+ #
70
+ # ==== Example
71
+ #
72
+ # my_system = Hitsuji.new # a new system
73
+ # my_item = my_system.item(:foo, 1) # a new item
74
+ # my_item2 = my_system.item(:qux, 2) # a second item
75
+ # items = [:foo, :qux]
76
+ # my_linker = my_system.linker(:baz, items) # a new linker
77
+ # my_op = my_system.operation(:op, my_linker, %{ # a new operation
78
+ # |arg1, arg2| arg1 + arg2
79
+ # }) # => :foo + :qux => 1 + 2 => 3
80
+ def operation(name, input, block)
81
+ new_operation = Operation.new(name, input, block)
47
82
  return new_operation
48
83
  end
49
84
 
50
- # binds object
51
- def bind(obj)
52
- @struct << obj
85
+ # Binds the inputted items to the system, allowing for the continous updating
86
+ # of the values within a system. This continuous updating is what gives
87
+ # Hitsuji its computational power.
88
+ #
89
+ # ==== Attributes
90
+ #
91
+ # * +*obj+ - the items, linkers and operation you want to bind
92
+ #
93
+ # ==== Example
94
+ #
95
+ # my_system = Hitsuji.new # a new system
96
+ # my_item = my_system.item(:foo, 1) # a new item
97
+ # my_item2 = my_system.item(:qux, 2) # a second item
98
+ # items = [:foo, :qux]
99
+ # my_linker = my_system.linker(:baz, items) # a new linker
100
+ # my_system.bind(my_item, my_item2, my_linker) # binds items + linker
101
+ def bind(*obj)
102
+ @struct.concat obj
53
103
  #update
54
104
  end
55
105
 
106
+ # Exports current state of system to a file. This process _does not export
107
+ # unbound items, linkers or operations!_ Creating new items doesn't automatically bind them to the
108
+ # system, even through they are a created with a method of a Hitsuji object.
109
+ #
110
+ # ==== Attributes
111
+ #
112
+ # * +directory+ - the path of the file to export the system (the extension
113
+ # of the file doesn't matter)
114
+ #
115
+ # ==== Example
116
+ #
117
+ # my_system = Hitsuji.new # a new system
118
+ # my_item = my_system.item(:foo, 1) # a new item
119
+ # my_system.bind(my_item) # binds item
120
+ # my_system.export('newfile.txt') # exports to 'newfile.txt'
121
+ def export(directory)
122
+ Transfer.export(directory, @struct)
123
+ end
124
+
125
+ # Imports file into a system, _overwriting anything already bound to the
126
+ # system_.
127
+ #
128
+ # ==== Attributes
129
+ #
130
+ # * +directory+ - the path of the file you want to import from
131
+ #
132
+ # ==== Example
133
+ #
134
+ # my_system = Hitsuji.new # a new system
135
+ # my_system.import('oldfile.txt') # imports from 'newfile.txt'
136
+ def import(directory)
137
+ @struct = Transfer.import(directory)
138
+ #update
139
+ end
140
+
141
+ private
142
+
143
+ def self.update # :nodoc:
144
+ # @struct.each do |val|
145
+ # case val.class
146
+ # when Item
147
+ #
148
+ # else
149
+ #
150
+ # end
151
+ # end
152
+ end
153
+
56
154
  end
data/lib/subsystem.rb CHANGED
@@ -1,7 +1,6 @@
1
- # item object
2
1
  class Item
3
2
 
4
- def initialize(name, value)
3
+ def initialize(name, value) # :nodoc:
5
4
  @name = name
6
5
  @value = value
7
6
  end
@@ -11,15 +10,14 @@ class Item
11
10
 
12
11
  end
13
12
 
14
- # linker object
15
13
  class Linker
16
-
17
- def initialize(name, value)
18
- for i in value
19
- if i.class != Linker and i.class != Item
20
- throw 'err'
21
- end
22
- end
14
+
15
+ 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
23
21
 
24
22
  @name = name
25
23
  @value = value
@@ -30,15 +28,14 @@ class Linker
30
28
 
31
29
  end
32
30
 
33
- # operation object
34
31
  class Operation
35
32
 
36
- def initialize(name, input, &func)
33
+ def initialize(name, input, block) # :nodoc:
37
34
  @name = name
38
35
  @input = input
39
- @block = func
36
+ @block = block
40
37
  end
41
38
 
42
- attr_reader :name, :input
39
+ attr_reader :name, :input, :block
43
40
 
44
41
  end
data/lib/transfer.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'subsystem'
2
+
3
+ class Transfer # :nodoc:
4
+
5
+ def self.export(directory, struct)
6
+ File.open(directory, "w") { |file| file.write(Marshal.dump(struct)) }
7
+ end
8
+
9
+ def self.import(directory)
10
+ File.open(directory, "r") { |file| return Marshal.load(file.read()) }
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hitsuji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-13 00:00:00.000000000 Z
11
+ date: 2018-08-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Hitsuji is a library that lets you easily create, edit, manage and apply
14
14
  custom management systems. It is scalable from library card databases to performance
@@ -20,6 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - lib/hitsuji.rb
22
22
  - lib/subsystem.rb
23
+ - lib/transfer.rb
23
24
  homepage: http://rubygems.org/gems/hitsuji
24
25
  licenses:
25
26
  - MIT