Initial Commit

This commit is contained in:
2020-06-07 09:02:02 -05:00
commit 5ea8d13653
8 changed files with 215 additions and 0 deletions

39
lib/storage.rb Normal file
View File

@@ -0,0 +1,39 @@
module TAC
module Storage
Group = Struct.new(:id, :name)
Action = Struct.new(:id, :group_id, :name, :enabled)
Value = Struct.new(:id, :action_id, :name, :type, :value)
def self.groups
@@_g ||= Array.new(15) { |i| Group.new(i, Faker::Book.title) }
end
def self.actions(group_id)
@@_a ||= Array.new(100) { |i| Action.new(i, groups.sample.id, Faker::Space.meteorite, true) }
@@_a.select { |a| a.group_id == group_id }
end
def self.values(action_id)
types = [:double, :float, :string, :boolean, :integer]
@@_v ||= Array.new(500) do |i|
v = Value.new(i, rand(100), Faker::Space.meteorite, types.sample)
v.value = case v.type
when :double, :float
rand(-1.0..1.0)
when :integer
rand(-1024..1024)
when :string
Faker::Quotes::Shakespeare.hamlet_quote
when :boolean
rand > 0.5
end
v
end
@@_v.select { |a| a.action_id == action_id }
end
end
end