Module: Tioga::HashArguments

Included in:
FigureMaker, FigureMaker
Defined in:
lib/Tioga/Utils.rb

Overview

This module is used internally by Tioga for handling the hash arguments that most of the functions take

Instance Method Summary collapse

Instance Method Details

#alt_names(dict, name1, name2) ⇒ Object



105
106
107
108
109
# File 'lib/Tioga/Utils.rb', line 105

def alt_names(dict, name1, name2)
    val = dict[name1]
    val = dict[name2] if val == nil
    return val
end

#check_dict(dict, names, str) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/Tioga/Utils.rb', line 91

def check_dict(dict,names,str)
    dict.each_key do |name|
        if names[name] == nil
            raise "Sorry: Invalid dictionary key for #{str} (#{name})."
        end
    end
end

#check_pair(ary, name, who_called) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/Tioga/Utils.rb', line 142

def check_pair(ary, name, who_called)
    return false if ary == nil
    if !(ary.kind_of?(Array) || ary.kind_of?(Dobjects::Dvector)) and ary.size == 2
        raise "Sorry: '#{name}' must be array [x,y] for #{who_called}."
    end
    return true
end

#complain_if_missing_numeric_arg(dict, name, alt_name, who_called) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/Tioga/Utils.rb', line 130

def complain_if_missing_numeric_arg(dict, name, alt_name, who_called)
    val = dict[name]
    val = dict[alt_name] if val == nil
    if val == nil
        raise "Sorry: Must supply '#{name}' in call to '#{who_called}'"
    end
    if !(val.kind_of?Numeric)
        raise "Sorry: Must supply numeric value for '#{name}' in call to '#{who_called}'"
    end
    return val
end

#get_dvec(dict, name, who_called) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/Tioga/Utils.rb', line 150

def get_dvec(dict, name, who_called)
    val = dict[name]
    if val == nil || !(val.kind_of? Dobjects::Dvector)
        raise "Sorry: '#{name}' must be a Dvector for '#{who_called}'"
    end
    return val
end

#get_if_given_else_default(dict, name, default) ⇒ Object



123
124
125
126
127
128
# File 'lib/Tioga/Utils.rb', line 123

def get_if_given_else_default(dict, name, default)
    return default if dict == nil
    val = dict[name]
    return val if val != nil
    return default
end

#get_if_given_else_use_default_dict(dict, name, default_dict) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/Tioga/Utils.rb', line 111

def get_if_given_else_use_default_dict(dict, name, default_dict)
    if dict != nil
        val = dict[name]
        return val if val != nil
    end
    val = default_dict[name]
    if val == nil
        raise "Sorry: failed to find value for '#{name}' in the defaults dictionary."
    end
    return val
end

#set_if_given(name, dict) ⇒ Object



99
100
101
102
103
# File 'lib/Tioga/Utils.rb', line 99

def set_if_given(name, dict)
    val = dict[name]
    return if val == nil
    eval "self." + name + " = val"
end