views:

109

answers:

3

Hi Guys,

I'm new at this, and I'm having trouble finding the proper way to phrase this in Ruby. And I don't know if the Ruby API in SketchUp is different. But, thats what I'm trying to use it for.

def self.initialize_job_info
    return{
        'salesperson' => ' = $pg_settings['salespersons'[['salesperson']['id']]] if ('on' = $pg_settings['salespersons'[['salesperson']['defsales']]])'

This is what I'm basically trying to do:

This part of the code works as it should

def self.initialize_job_info
    return{
        'salesperson' => ''

It sets an empty form's initial value of job_info['salesperson']'s value to ' ' if no pre-existing value is found.

So, there is a value I want to place in the Hash that is being passed from $pg_settings.

The value I want is, and I hope this make sense, the value of this specific 'id'

$pg_settings['salespersons'] {//which is a list of 'salesperson'
    <salesperson> id="561" name="name" phone="phone number" defsales="on" email="email" </salesperson>

if (defsales == "on") then 'salesperson' => 'value="id"'

Does this make sense?

I'm pulling my hair out, so any help you can give on this would be great.

A: 

if those names not inside the quotes are variables that you want to get the values from it should probably be:

'salesperson' => " = $pg_settings[#{salespersons}[[#{salesperson}][#{id}]]] if (#{on} = $pg_settings[#{salespersons}[[#{salesperson}][#{defsales}]]])"

but as Geo said, more detail on the actual purpose/intent would help

BTW, that construc tis called string interpolation (http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation)

Chris Hulan
A: 

If you want to interpolate the strings, as in include their value in a string, then maybe this examples can help you:

a = "a string"
b = "this is"
c = "#{b} #{a}"

In the example above, c will have the value: this is a string . Also, while interpolating, valid Ruby code is accepted. So, this is ok too:

c = "#{ b.sub("this","") } #{a}"

And in this case, c will have the value is a string . So, if you need to interpolate something, first think about how you would do it using normal code, and then just add #{} around it.

Geo
A: 

I figured it out.

Here is the working code

def self.initialize_job_info
    return{
        'salesperson' => self.default,
    }
end

def self .default
    salespersons = $pg_settings['salespersons']
    salespersons.each do |salesperson|

    if (salesperson['defsales'] == 'on')
        return salesperson['id']
        end
    end
end

Looks like I was a long way off.......lol

Eric Hunt