Jano Svitok
8/30/2006 7:54:00 PM
On 8/30/06, eatmyjunk@gmail.com <eatmyjunk@gmail.com> wrote:
> I have a few variables for a program I am attempting to write that I
> need to be able to read into my script. However, certain ones take on a
> different scope than others, so I would like to separate them out into
> groups (in different files, hopefully). It is for film production, so
> I'll try to break it down with that in mind. I hope I'm clear enough.
>
> The groupings are:
> 1. Variables that are used every time the script is run, and never (or
> nearly never) change, such as the project name.
> 2. Variables that remain the same for every time the script is run on
> certain shot, but are unique to only that shot, such as the length.
> 3. Variables that change every time the script runs, such as the render
> version or the date (not taken from the system time, unfortunately).
> These variables should also be able to compute what the correct file
> for group 2 variables are.
> 4. Variables that are calculated from the previous 3 groups and are
> unique with each running of the script, such as the filename of the
> file to be rendered, and its output.
>
> What I have got working so far is to set all my variables in four
> files, however, I have to manually specify them in the main .rb script.
> Additionally, I can only seem to get it to work with $variables, and
> nothing else. For now, I'd like to have the ruby script run with a flag
> to tell it where to start looking for the variables, and be able to
> pass them on and calculate them until they all get back to the main
> script.
>
> Here's an example:
>
> (in instance_variables.rb)
> $shotScene = 10
> $shotShot = 1
> $shotVersion = 4
> ...
>
> (in main.rb)
> require 'environment_variables.rb'
> require 'instance_variables.rb'
> require 'shot_variables.rb'
> require 'calculated_variables.rb'
> ...
>
> Although I have not yet set it up, I also want to integrate this group
> of variables (1, 2, 3 and 4) into a database (rails?), so that I can
> have a sort of queue (queued, currently running, and logged entries).
> Although I'll try to muddle my way through a bit more before I
> integrate a db back end, I need to have a solution that can look
> forward to that eventuality.
>
> Cheers, and thanks,
> Martin
Hi,
this is what you can do (among other ways):
(using YAML as storage format)
1. create classes that hold the variables, possibly using Struct or OpenStruct.
There would be Project, Shot, Run, etc.
Shot = Struct.new(:scene, :shot, :version)
2. add methods that calculate dependent data (i.e. Shot#project_file)
3. add methods that initialize data from a Hash. It's easier to
edit/create YAML files with Hash than with objects, but the other way
is not that harder, so you may try it as well.
def Shot.load(filename)
Shot.new(YAML.load_file(filename))
end
or just
def Shot.load(filename)
YAML.load(filename)
end
Alternatively, just go for ActiveRecord, define your structures and relations.
The first approach will be a bit easier to setup (i.e. no setup ;-)
the second is easier in the long term, if you want to use the
database, create a web interface, etc.