Class: Panomosity::OptimisationVariable
- Inherits:
-
Object
- Object
- Panomosity::OptimisationVariable
- Defined in:
- lib/panomosity/optimisation_variable.rb
Constant Summary collapse
- START_LINE =
'v'
- @@attributes =
%i(w h f v Ra Rb Rc Rd Re Eev Er Eb r p y TrX TrY TrZ Tpy Tpp j a b c d e g t Va Vb Vc Vd Vx Vy Vm n)
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #attributes ⇒ Object
-
#initialize(attributes) ⇒ OptimisationVariable
constructor
A new instance of OptimisationVariable.
- #to_s ⇒ Object
Constructor Details
#initialize(attributes) ⇒ OptimisationVariable
Returns a new instance of OptimisationVariable.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/panomosity/optimisation_variable.rb', line 30 def initialize(attributes) @attributes = attributes # conform data types @attributes.each do |key, value| next if %i(raw).include?(key) if value.respond_to?(:include?) && value.include?('.') @attributes[key] = value.to_f else @attributes[key] = value.to_i end end end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/panomosity/optimisation_variable.rb', line 10 def self.all @optimization_variables end |
.parse(pto_file) ⇒ Object
6 7 8 |
# File 'lib/panomosity/optimisation_variable.rb', line 6 def self.parse(pto_file) @optimization_variables = pto_file.each_line.map { |line| parse_line(line) }.compact end |
.parse_line(line) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/panomosity/optimisation_variable.rb', line 14 def self.parse_line(line) parts = line.split(' ') if parts.first == START_LINE parts = parts[1..(parts.count-1)] data = parts.each_with_object({}) do |part, hash| attribute = @@attributes.find { |attr| part[0] == attr.to_s } next unless attribute hash[attribute] = part.sub(attribute.to_s, '') end data[:raw] = line new data end end |
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/panomosity/optimisation_variable.rb', line 43 def [](key) @attributes[key] end |
#[]=(key, value) ⇒ Object
47 48 49 |
# File 'lib/panomosity/optimisation_variable.rb', line 47 def []=(key, value) @attributes[key] = value end |
#attributes ⇒ Object
66 67 68 |
# File 'lib/panomosity/optimisation_variable.rb', line 66 def attributes @attributes.keep_if { |k, _| !%i(raw).include?(k) } end |
#to_s ⇒ Object
61 62 63 64 |
# File 'lib/panomosity/optimisation_variable.rb', line 61 def to_s line_values = @@attributes.map { |attribute| "#{attribute}#{self.send(attribute)}" if self.send(attribute) } "v #{line_values.compact.join(' ')}\n" end |