Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Separation of Variables

Reply
Thread Tools

Separation of Variables

 
 
eatmyjunk@gmail.com
Guest
Posts: n/a
 
      08-30-2006
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

 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      08-30-2006
On 8/30/06, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code-separation in ASP.NET 2.0 Michael ASP .Net 3 11-12-2005 02:06 PM
Templating - complete separation of design/coding? Chris Ashley ASP .Net 1 08-19-2005 01:24 PM
Header line of table giving me separation lines tshad ASP .Net 2 12-02-2004 07:01 PM
Anti-aliasing, Color Separation, etc. Paul H. Digital Photography 22 12-22-2003 10:36 AM
Question on view and code separation Wayne Liu ASP .Net 0 07-25-2003 05:26 AM



Advertisments