Class: Panomosity::PanoramaVariable

Inherits:
Object
  • Object
show all
Defined in:
lib/panomosity/panorama_variable.rb

Constant Summary collapse

@@attributes =
%i(p w h f v n E R)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ PanoramaVariable

Returns a new instance of PanoramaVariable.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/panomosity/panorama_variable.rb', line 28

def initialize(attributes)
  @attributes = attributes
  # conform data types
  @attributes.each do |key, value|
    next if %i(n 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

.allObject



9
10
11
# File 'lib/panomosity/panorama_variable.rb', line 9

def self.all
  @panorama_variables
end

.parse(pto_file) ⇒ Object



5
6
7
# File 'lib/panomosity/panorama_variable.rb', line 5

def self.parse(pto_file)
  @panorama_variables = pto_file.each_line.map { |line| parse_line(line) }.compact
end

.parse_line(line) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/panomosity/panorama_variable.rb', line 13

def self.parse_line(line)
  parts = line.split(' ')
  if parts.first == 'p'
    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



41
42
43
# File 'lib/panomosity/panorama_variable.rb', line 41

def [](key)
  @attributes[key]
end

#[]=(key, value) ⇒ Object



45
46
47
# File 'lib/panomosity/panorama_variable.rb', line 45

def []=(key, value)
  @attributes[key] = value
end

#attributesObject



64
65
66
# File 'lib/panomosity/panorama_variable.rb', line 64

def attributes
  @attributes.keep_if { |k, _| !%i(raw).include?(k) }
end

#to_sObject



59
60
61
62
# File 'lib/panomosity/panorama_variable.rb', line 59

def to_s
  line_values = @@attributes.map { |attribute| "#{attribute}#{self.send(attribute)}" }
  "p #{line_values.join(' ')}\n"
end