Class: Qt::Commander::Creator::InfoObject

Inherits:
Object
  • Object
show all
Defined in:
lib/qt/commander/creator/info_object.rb

Direct Known Subclasses

Profile, Toolchain, Version

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ InfoObject

Returns a new instance of InfoObject.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/qt/commander/creator/info_object.rb', line 20

def initialize info
  self.class.keys.each do |name, orig_name, opts|
    orig_name = [orig_name] unless orig_name.is_a? Array
    val = info
    
    orig_name.each do |orig|
      val = val.fetch(orig) if val.key? orig or !opts[:optional]
    end
    
    instance_variable_set :"@#{name}", val unless val == info
  end
end

Class Method Details

.key(name, orig_name, opts = {}) ⇒ Object



5
6
7
8
9
# File 'lib/qt/commander/creator/info_object.rb', line 5

def self.key name, orig_name, opts={}
  @keys ||= []
  @keys << [ name, orig_name, opts ]
  attr_reader name
end

.keysObject



11
12
13
# File 'lib/qt/commander/creator/info_object.rb', line 11

def self.keys
  @keys ||= []
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/qt/commander/creator/info_object.rb', line 16

def [] key
  instance_variable_get :"@#{key}"
end