Module: Methods

Included in:
Session
Defined in:
lib/puer/session.rb

Instance Method Summary collapse

Instance Method Details

#bool(name) ⇒ Object



86
87
88
# File 'lib/puer/session.rb', line 86

def bool(name)
  Converter.new(name) {|v| v==1}
end

#class_info_for(class_name) ⇒ Object



46
47
48
# File 'lib/puer/session.rb', line 46

def class_info_for(class_name)
  @classes[class_name]
end

#classes(class_hash) ⇒ Object



50
51
52
53
54
# File 'lib/puer/session.rb', line 50

def classes(class_hash)
  class_hash.each do |key, value|
    @classes[key] = ClassInfo.new(*value)
  end
end

#color(name) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/puer/session.rb', line 94

def color(name)
  Converter.new(name) do |v| 
    case v
    when /NS(?:Calibrated|Device)RGBColorSpace (\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)/
      rgba($1, $2, $3, $4)
    when /NS(?:Calibrated|Device)WhiteColorSpace (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)/
      rgba($1, $1, $1, $2)
    when /NSCustomColorSpace Generic Gray colorspace (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)/
      rgba($1, $1, $1, $2)
    end
  end
end

#converter_for(property_name) ⇒ Object



42
43
44
# File 'lib/puer/session.rb', line 42

def converter_for(property_name)
  @properties[property_name]
end

#font(name) ⇒ Object



107
108
109
110
111
# File 'lib/puer/session.rb', line 107

def font(name)
  Converter.new(name) do |v| 
    {:fontFamily => v['Family'], :fontSize => v['Size']}
  end
end

#full_log(severities = []) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/puer/session.rb', line 18

def full_log(severities=[])
  excluded = @log.map(&:first).uniq - severities
  (excluded.empty? ? '' : "There were log entries of severity: #{excluded.join ', '}\n") +
  @log.map do |severity, message|
    "[#{severity}] #{message}" if severities.include? severity
  end.compact.join("\n")
end

#has_errors?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/puer/session.rb', line 26

def has_errors?
  @log.any? {|severity, message| severity == :error}
end

#hex(v) ⇒ Object

Color helper methods



72
73
74
# File 'lib/puer/session.rb', line 72

def hex(v)
  "%02x" % (v.to_f*255).round
end

#ignore_class?(class_name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/puer/session.rb', line 34

def ignore_class?(class_name)
  @ignore_classes.include? class_name
end

#ignore_classes(*names) ⇒ Object



62
63
64
# File 'lib/puer/session.rb', line 62

def ignore_classes(*names)
  @ignore_classes += names
end

#ignore_properties(*names) ⇒ Object



56
57
58
59
60
# File 'lib/puer/session.rb', line 56

def ignore_properties(*names)
  names.to_a.each do |o|
    @ignore_properties << o if o
  end if names
end

#ignore_property?(property_name) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/puer/session.rb', line 38

def ignore_property?(property_name)
  @ignore_properties.include? property_name
end

#log(severity, message) ⇒ Object



30
31
32
# File 'lib/puer/session.rb', line 30

def log(severity, message)
  @log.push [severity, message]
end

#lookup(name, hash) ⇒ Object



90
91
92
# File 'lib/puer/session.rb', line 90

def lookup(name, hash)
  Converter.new(name) {|v| hash[v]}
end

#parse_file(file) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/puer/session.rb', line 9

def parse_file(file)
  data = Plist::parse_xml( %x[ibtool #{file} --hierarchy --objects --connections] )
  @out = data['com.apple.ibtool.document.hierarchy'].map {|hierarchy| NodeInfo.for hierarchy, data['com.apple.ibtool.document.objects'], self}.compact
  data['com.apple.ibtool.document.connections'].each do |connection|
    # TODO
  end
  @out
end

#properties(properties_hash) ⇒ Object



66
67
68
# File 'lib/puer/session.rb', line 66

def properties(properties_hash)
  @properties.merge! properties_hash
end

#rgba(r, g, b, a) ⇒ Object



76
77
78
# File 'lib/puer/session.rb', line 76

def rgba(r, g, b, a)
  "##{hex(r)}#{hex(g)}#{hex(b)}#{hex(a)}"
end

#val(name) ⇒ Object

Methods for converter creation in config file



82
83
84
# File 'lib/puer/session.rb', line 82

def val(name)
  Converter.new(name)
end

#vector(x, y) ⇒ Object



113
114
115
# File 'lib/puer/session.rb', line 113

def vector(x, y)
  MultiConverter.new([x, y], /\{(\d+), (\d+)\}/) {|v| v.to_i}
end